Wednesday , January 17 2018
most suggested
Home / c-program / C Program – Addition of two Matrices Example

# C Program – Addition of two Matrices Example

C Program to Addition of two Matrices.

## Addition of two Matrices :

```
#define ROWS 3
#define COLS 4
#include<stdio.h>
int main(void)
{
int i,j;
int matx1[ROWS][COLS],matx2[ROWS][COLS],matx3[ROWS][COLS];
printf("Enter Matrix 1 Values(%dx%d) : \n",ROWS,COLS);

for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
scanf("%d",&matx1[i][j]);
}
}

printf("Enter Matrix 2 Values (%dx%d): \n",ROWS,COLS);
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
scanf("%d",&matx2[i][j]);
}
}

for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
matx3[i][j] = matx1[i][j] + matx2[i][j];
}

}

printf("The resultant Matrix 3 is :\n");
for(i=0; i<ROWS; i++)
{
for(j=0; j<COLS; j++)
printf("%5d",matx3[i][j]);
printf("\n");
}
return 0;
}

```

Enter Matrix 1 Values(3×4) :
1 3 5 7
2 4 6 8
3 5 7 9
Enter Matrix 2 Values (3×4):
3 5 7 9
2 4 6 8
1 3 5 7
The resultant Matrix 3 is :
4    8   12   16
4    8   12   16
4    8   12   16

Happy Learning 🙂