Write a C Program Program ForAddition of two matrices
#define ROW 3
#define COL 4
#include<stdio.h>
int main(void)
{
int i,j,mat1[ROW][COL],mat2[ROW][COL],mat3[ROW][COL];
printf("Enter matrix mat1(%dx%d)row-wise :\n",ROW,COL);
for(i=0; i<ROW; i++)
for(j=0; j<COL; j++)
scanf("%d",&mat1[i][j]);
printf("Enter matrix mat2(%dx%d)row-wise :\n",ROW,COL);
for(i=0; i<ROW; i++)
for(j=0; j<COL; j++)
scanf("%d",&mat2[i][j] );
/*Addition*/
for(i=0; i<ROW; i++)
for(j=0; j<COL; j++)
mat3[i][j] = mat1[i][j] + mat2[i][j];
printf("The resultant matrix mat3 is :\n");
for(i=0; i<ROW; i++)
{
for(j=0; j<COL; j++)
printf("%5d",mat3[i][j]);
printf("\n");
}
return 0;
}
Output
Enter matrix mat1(3x4)row-wise :
12 13 14 15
16 17 18 19
20 21 22 23
Enter matrix mat2(3x4)row-wise :
24 25 26 27
28 29 30 31
32 33 34 35
The resultant matrix mat3 is :
36 38 40 42
44 46 48 50
52 54 56 58