Sunday, 20 May 2012

Write a program to add the two given 3 x 3 matrices


//program to add the two matrices
void main()
{
int i,j,a[3][3],b[3][3],c[3][3];
clrscr();
printf("Enter the elements of 3*3 A matrix ");
for(i=0;i<3;i++)
{
 for(j=0;j<3;j++)
 {
 scanf("%d",&a[i][j]);
 }
}
printf("Enter the elements of 3*3 B matrix ");
for(i=0;i<3;i++)
{
 for(j=0;j<3;j++)
 {
 scanf("%d",&b[i][j]);
 }
}
for(i=0;i<3;i++)
{
 for(j=0;j<3;j++)
 {
 c[i][j]=a[i][j]+b[i][j];
 }
}
printf("The result after adding the above mentioned matrixes is given bellow\n");
for(i=0;i<3;i++)
{
 for(j=0;j<3;j++)
 {
 printf("%d ",c[i][j]);
 }
 printf("\n");
}
getch();
}
Output
Enter the elements of 3*3 A matrix
1 2 3
4 5 6
7 8 9
Enter the elements of 3*3 B matrix
3 2 1
6 5 4
9 8 7
The result after adding the above mentioned matrixes is given bellow
4 4 4
10 10 10
        16 16 16

No comments:

Post a Comment