Sunday, 11 December 2011

Write a program to input first 3*3 array , second 3*3 array and find out its sum of matrics in c

#include
#include
main()
{
int arr1[3][3],arr2[3][3],sum[3][3];
int i,j;
clrscr();
printf("Enter First 3 X 3 array:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&arr1[i][j]);
}
}
printf("Enter Second 3 X 3 array :\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&arr2[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
sum[i][j]=arr1[i][j]+arr2[i][j];
}
}
printf("The sum of the matrix is\n");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
{
printf("sum[%d][%d] = %d\t\t",i,j,sum[i][j]);
}
}
getch();

}



OUTPUT


Enter first 3 X 3 array :

1
2
3
4
5
6
7
8
9

Enter second 3 X 3 array :

1
2
3
4
5
6
7
8
9

the sum of the matrix is

sum[0][0] = 2 sum[0][1] = 4 sum[0][2] = 6
sum[1][0] = 8 sum[1][1] = 10 sum[1][2] = 12
sum[2][0] = 14 sum[2][1] = 16 sum[2][2] = 18

No comments:

Post a Comment