Check The Programming Section
Two functions are used:
input function to take the input
print function to print the matrix
Before performe the addition if condition written inside the main() will check the dimenstion of two matrixes and the result will be saved to res matrix.
#include<stdio.h>
#define ROW 10
#define COL 10
void input(int mat[][COL],int row, int col){
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
scanf("%d",&mat[i][j]);
}
}
}
void print(int mat[][COL],int row, int col){
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
printf("%d\t",mat[i][j]);
}
printf("\n");
}
}
int main(){
int mat1[ROW][COL];
int mat2[ROW][COL];
int res[ROW][COL];//save the addition
int row1, row2, col1, col2;
printf("Enter number of rows and cols for matrix1::");
scanf("%d %d",&row1, &col1);
printf("Enter number of rows and cols for matrix2::");
scanf("%d %d",&row2, &col2);
printf("Enter the values for first matrix::\n");
input(mat1,row1,col1);
printf("Enter the values for first matrix::\n");
input(mat2,row2,col2);
printf("The first matrix::\n");
print(mat1,row1,col1);
printf("The Second Matrix::\n");
print(mat2,row2,col2);
if(row1==row2 && col1==col2){
for(int i=0;i<row1;i++){
for(int j=0;j<col1;j++){
res[i][j] = mat1[i][j] + mat2[i][j];
}
}
printf("The resultant matrix.....\n");
print(res,row1,col1);
}
else{
printf("Matrix dimenstion are not same");
}
}