-
Notifications
You must be signed in to change notification settings - Fork 3
/
addition_matrix.c
89 lines (75 loc) · 1.73 KB
/
addition_matrix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdio.h>
int main(){
// First Matrix
int n,m;
printf("Input rows and columns for First matrix: ");
scanf("%d %d",&m,&n);
int A[m][n];
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
printf("The %dth index of %dth element is: ",i,j);
scanf("%d", &A[i][j]);
}
printf("\n");
}
// Second Matrix
int a,b;
printf("Input rows and columns of the Second matrix: ");
scanf("%d %d",&a,&b);
int B[a][b];
if (m != a || n != b)
{
printf("OOPS!!! Your Matrix is not suitable for Addition!!!!.");
return 0;
}
for (int i = 0; i < a; i++)
{
for (int j = 0; j < b; j++)
{
printf("The %dth index of %dth element is: ",i,j);
scanf("%d", &B[i][j]);
}
printf("\n");
}
// Printing the Matrix.
printf("Your first Array is:\n");
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
printf("%d ",A[i][j]);
}
printf("\n");
}
printf("Your Second Array is:\n");
for (int i = 0; i < a; i++)
{
for (int j = 0; j < b; j++)
{
printf("%d ",B[i][j]);
}
printf("\n");
}
// Addition of Matrix
int R[a][n];
for (int i = 0; i < a; i++)
{
for (int j = 0; j < n; j++)
{
R[i][j]=A[i][j]+B[i][j];
}
printf("\n");
}
printf("Your Final Array is:\n");
for (int i = 0; i < a; i++)
{
for (int j = 0; j < b; j++)
{
printf("%d ",R[i][j]);
}
printf("\n");
}
return 0;
}