-
Notifications
You must be signed in to change notification settings - Fork 4
/
add2matrix.c
61 lines (60 loc) · 1.34 KB
/
add2matrix.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
#include <stdio.h>
void main()
{
int m, n, i, j;
printf("Enter the no. of rows of matrix:\n");
scanf("%d", &m);
printf("Enter the no. of columns of matrix:\n");
scanf("%d", &n);
int a[m][n], b[m][n], c[m][n];
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf("Enter the a[%d][%d] element:\n", i, j);
scanf("%d", &a[i][j]);
}
}
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf("Enter the b[%d][%d] element:\n", i, j);
scanf("%d", &b[i][j]);
}
}
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
c[i][j] = a[i][j] + b[i][j];
}
}
printf("\nThe first matrix is:\n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf("\t%d", a[i][j]);
}
printf("\n");
}
printf("\nThe second matrix is:\n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf("\t%d", b[i][j]);
}
printf("\n");
}
printf("\nThe matrix is:\n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf("\t%d", c[i][j]);
}
printf("\n");
}
}