-
Notifications
You must be signed in to change notification settings - Fork 0
/
addomatrix.c
44 lines (44 loc) · 902 Bytes
/
addomatrix.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
//%%writefile matrix_addition.c
#include <stdio.h>
int main()
{
int m, n, i, j;
printf("Enter the no. of rows : ");
scanf("%d",&m);
printf("Enter the no. columns : ");
scanf("%d",&n);
int a[m][n], b[m][n], sum[m][n];
printf("Enter the elements of first matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the elements of second matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
sum[i][j] = a[i][j] + b[i][j];
}
}
printf("Sum of the matrices:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",sum[i][j]);
}
printf("\n");
}
return 0;
}