-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray_matrixaddition.c
36 lines (36 loc) · 1000 Bytes
/
array_matrixaddition.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
#include <stdio.h>
void main()
{
int i,j,r1, c1, r2, c2;
printf("Enter the first matrix(m1)' no .of row and column respectively : ");
scanf("%d %d", &r1, &c1);
printf("Enter the second matrix(m2)' no .of row and column respectively : ");
scanf("%d %d", &r2, &c2);
if (r1 == r2 && c1 == c2)
{
int m1[r1][c1], m2[r1][c1];
for (i = 0; i < r1; i++)
{
for (j = 0; j < c1; j++)
{
printf("Enter the elememt m1[%d][%d]=", i + 1, j + 1);
scanf("%d", &m1[i][j]);
printf("Enter the elememt m2[%d][%d]=", i + 1, j + 1);
scanf("%d", &m2[i][j]);
}
}
printf("\n m1+m2= \n");
for (i = 0; i < r1; i++)
{
for (j = 0; j < c1; j++)
{
printf("%2d",m1[i][j]+m2[i][j]);
}
printf("\n");
}
}
else
{
printf("Matrix addition is not possible");
}
}