C Program to Add Two Matrices Using 2D Array
#include<stdio.h>
#include<conio.h>
main()
{
int i,j,mat1[3][3],mat2[3][3],sum[3][3];
printf("enter the elements for matrix first\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&mat1[i][j]);
}
}
printf("enter the elements for matrix second\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&mat2[i][j]);
}
}
/*process of adding matrix 1 and matrix 2*/
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
sum[i][j]=mat1[i][j]+mat2[i][j];
}
}
printf("the sum of two matrix is:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",sum[i][j]);
}
printf("\n");
}
getch();
}
No comments:
Post a Comment