You are on page 1of 1

//add two matrix

#include <stdio.h>
#include <conio.h>
main()
{
int a[3][3], b[3][3], c[3][3];
int i, j;
/* read values for the input matrix a */
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf( %d , &a[i][j]);
/* read values for the input matrix b */
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf( %d , &b[i][j]);
/* initialize the output matrix c with all elements 0 */
for(i=0;i<3;i++)
for(j=0;j<3;j++)
c[i][j] = 0;
/* add matrix a and b and store the result in matrix c */
for(i=0;i<3;i++)
for(j=0;j<3;j++)
c[i][j] = a[i][j] + b[i][j];
/* print the resultant matrix c */
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf( %d , c[i][j]);
printf( \n );
}
}

You might also like