C program to find sum of two matrices of size 3×3

/* C program to find sum of two matrices of size 3×3 */

#include <stdio.h>

int main()
{
int A[3][3];
int B[3][3];
int C[3][3];

int row, col;

/* Input elements in first matrix*/
printf(“Enter elements in matrix A of size 3×3: \n”);
for(row=0; row<3; row++)
{
for(col=0; col<3; col++)
{
scanf(“%d”, &A[row][col]);
}
}

/* Input elements in second matrix */
printf(“\nEnter elements in matrix B of size 3×3: \n”);
for(row=0; row<3; row++)
{
for(col=0; col<3; col++)
{
scanf(“%d”, &B[row][col]);
}
}
/* C= A +B */
for(row=0; row<3; row++)
{
for(col=0; col<3; col++)
{
C[row][col] = A[row][col] + B[row][col];
}
}

/* Print the value of resultant matrix C */
printf(“\nSum of matrices A+B = \n”);
for(row=0; row<3; row++)
{
for(col=0; col<3; col++)
{
printf(“%d “, C[row][col]);
}
printf(“\n”);
}

return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>