#include<stdio.h>
///matrix summation
int main()
{
int a[10][10], b[10][10], sum[10][10], i, j, m,n,p,q;
printf("Enter the order of first matrix: ");
scanf("%d%d",&m,&n);
printf("Enter the order of second matrix: ");
scanf("%d%d",&p,&q);
if(m!=p && n!=q){
printf("Error match!!");
exit(0);
}
printf("Enter first matrix: \n");
for(i = 0 ; i < m; i++){
for(j = 0; j < n; j++)
scanf("%d", &a[i][j]);
}
printf("Enter second matrix: \n");
for(i = 0 ; i < p; i++){
for(j = 0; j < q; j++)
scanf("%d", &b[i][j]);
}
for(i = 0 ; i < m; i++){
for(j = 0; j < n; j++)
sum[i][j] = a[i][j] + b[i][j];
}
printf("The sum of the matrix is :\n");
for(i = 0 ; i < m; i++){
for(j = 0; j < n; j++){
printf("%d ", sum[i][j]);
}
printf("\n");
}
return 0;
}
No comments:
Post a Comment