How to write a c program to matrix addition in c programming ?
Solution:
#include <stdio.h>
int main()
{
int i, j, m, n;
int a[10][10], b[10][10], c[10][10];
printf("Enter m: ");
scanf("%d", &m);
printf("Enter n: ");
scanf("%d", &n);
for(i = 0; i < m; i++)
for(j = 0; j < n; j++)
{
printf("[%d %d] = ", i, j);
scanf("%d", &a[i][j]);
}
printf("\n");
for(i = 0; i < m; i++)
for(j = 0; j < n; j++)
{
printf("[%d %d] = ", i, j);
scanf("%d", &b[i][j]);
}
for(i = 0; i < m; i++)
for(j = 0; j < n; j++)
c[i][j] = a[i][j] + b[i][j];
printf("\n");
for(i = 0; i < m; i++)
{
for(j = 0; j < n; j++)
printf("%d\t", a[i][j]);
printf("\n");
}
printf("\n");
for(i = 0; i < m; i++)
{
for(j = 0; j < n; j++)
printf("%d\t", b[i][j]);
printf("\n");
}
printf("\n");
for(i = 0; i < m; i++)
{
for(j = 0; j < n; j++)
printf("%d\t", c[i][j]);
printf("\n");
}
return 0;
}