Add two 3X3 matrix
C Program
#include <stdio.h>
#include <stdlib.h>
int main()
{
int Mat1[3][3], Mat2[3][3], Mat3[3][3];
int i,j;
printf("Matrix 1:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("Enter element [%d][%d]: ", (i+1),(j+1));
scanf("%d",&Mat1[i][j]);
}
}
printf("Matrix 2:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("Enter element [%d][%d]: ", (i+1),(j+1));
scanf("%d",&Mat2[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
Mat3[i][j]=Mat1[i][j]+Mat2[i][j];
}
}
printf("The sum of the two matrix is:");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d " ,Mat3[i][j]);
}
}
}
0 Comments:
Post a Comment