Let us take two matrices namely A and B;
/**
* Author : Berk Soysal
*/
#include <stdio.h>
#define ROW 2
#define COL 3
int main()
{
int a[ROW][COL] = {5, 3, 7, 0, 1, 2};
int b[ROW][COL] = {1, 2, 3, 4, 5, 6};
int c[ROW][COL];
int i, j;
printf("Matrix A:\n");
for(i=0; i<ROW; i++)
{
for(j=0; j<COL; j++)
printf("%4d",a[i][j]);
printf("\n");
}
printf("Matrix B:\n");
for(i=0; i<ROW; i++)
{
for(j=0; j<COL; j++)
printf("%4d",b[i][j]);
printf("\n");
}
printf("Resulting Matrix C:\n");
for(i=0; i<ROW; i++)
{
for(j=0; j<COL; j++)
{
c[i][j] = a[i][j] + b[i][j];
printf("%4d",c[i][j]);
}
printf("\n");
}
return 0;
}
Result
If you have any questions or comments, please leave a comment below. Thanks.
Keywords: CCode Snippets
Disqus Comments Loading..