-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddmatrix.c
62 lines (49 loc) · 1.09 KB
/
addmatrix.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
#include<stdio.h>
#include<conio.h>
#define max_row 10
#define max_cols 10
int main()
{
int rows,column;
int a[max_row][max_cols],b[max_row][max_cols],sum[max_row][max_cols];
printf("Enter the number of rows\n");
scanf("%d",&rows);
printf("Enter the number of colummns\n");
scanf("%d",&column);
//taking first matrix
for(int i=0; i<rows; i++)
{
for(int j=0; j<column; j++)
{
printf("Enter the first matrix\n");
scanf("%d", &a[i][j]);
}
}
//taking 2nd matrix
for(int i=0; i<rows; i++)
{
for(int j=0; j<column; j++)
{
printf("Enter the second matrix elements\n");
scanf("%d", &b[i][j]);
}
}
//sum of 2 matrix
for(int i=0; i<rows; i++ )
{
for(int j=0; j<column; j++)
{
sum[i][j]=a[i][j]+b[i][j];
}
}
//output
for(int i=0; i<rows; i++)
{
for(int j=0; j<column; j++)
{
printf("%d\t",sum[i][j]);
}
printf("\n");
}
getch();
}