Radical Developers welcomes all the visitors to be a member of the team. Come join us. Its all about open-source concept. All Programs are written and tested in MacOS X, Unix, Linux and may not match with the outputs of Turbo C++ in Windows

Sunday, January 9, 2011

Write a Program to add any two 3x3 matrices.


Source Code :

#include<stdio.h>
void main()
{
      int a[3][3],b[3][3],c[3][3],i,j;
      clrscr();
      printf("\nEnter Matrix A : ");
      for(i=0;i<3;i++)
            for(j=0;j<3;j++)
                  scanf("%d",&a[i][j]);
      printf("\nEnter Matrix B : ");
      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("\nAfter Addition : \n");
      for(i=0;i<3;i++)
      {
            for(j=0;j<3;j++)
                  printf("%d\t",c[i][j]);
            printf("\n");
      }
      getch();
}

Output :

Enter Matrix A : 5 6 9 8 7 4 1 2 3

Enter Matrix B : 2 5 6 9 8 4 3 1 7

After Addition :
7     11    15
17    15    8
4     3     10

No comments:

Post a Comment