A program in C for Matrix multiplication of 3x3 matrix

 #include<stdio.h>
#include<conio.h>
int a[3][3],b[3][3],c[3][3];
void main()
{
int i,j,k,sum;
clrscr();
 printf("enter values");
for(i=0;i<3;i++)
{                                     //input  matrix a
for(j=0;j<3;j++)
{

 scanf("%d",&a[i][j]);
 printf("\n");
 }
}
 clrscr();
 printf("enter values");
 for(i=0;i<3;i++)
{                                  //input  matrix b
for(j=0;j<3;j++)
{

 scanf("%d",&b[i][j]);
 printf("\n");
 }
}
for(i=0;i<3;i++)
{                                     //calculating sum
  for(j=0;j<3;j++)
  {
     sum=0;
    for(int k=0;k<=2;k++)
    {
       sum=sum+a[i][k]*b[k][j];
     c[i][j]=sum;
      }
   }
 }
 clrscr();
 printf("after multiplication matrix is\n\n");
 for(i=0;i<3;i++)
{                               //printing
for(j=0;j<3;j++)
{
 printf(" %d ",c[i][j]);
}
 printf("\n");

}
getch();
}
Share on Google Plus

About Ayush Saluja

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

Follow by Email