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 multiply 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("\nInput Matrix A : ");
      for(i=0;i<3;i++)
            for(j=0;j<3;j++)
                  scanf("%d",&a[i][j]);   //Input in Matrix A
      printf("\nInput Matrix B : ");
      for(i=0;i<3;i++)
            for(j=0;j<3;j++)
                  scanf("%d",&b[i][j]);   //Input in Matrix B
      for(i=0;i<3;i++)
            for(j=0;j<3;j++)
                 c[i][j]=a[i][j]*b[j][i]; //Multiplication
      printf("\nMultiplication of Matrix A & B : \n");
      for(i=0;i<3;i++)
      {
            printf("\n");
            for(j=0;j<3;j++)
            {
                printf("%d\t",c[i][j]); //Display Resultant Matrix
            }
      }
      getch();
}

Output :

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

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

Multiplication of Matrix A & B :
20    9     54
4     45    64
7     24    7

No comments:

Post a Comment