Let us take two matrices namely A and B;
![matrix addition berk soysal](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXa4YOA__1ILL-9MGWFZO9xM56iH6hfEuwbGAivZPuNXFN4Ogw-G_Nwz0j2Njjdi79YESAkUfzTjYZm2OTCZbmD4riMgOgWsr3HL6uyekZGjBTY-V7xuGs9lHiVzLXCav3tkzcyBZO85Q/s320/7ec5cd9a9e5ef6cf052bfeed0cb8f0b3.png)
/**
* 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..