WAP to multipy two matrices

#include<stdio.h>
 #include<stdlib.h>

 int main()
 {
 int a[10][10],b[10][10],c[2][2]={0,0,0,0},i,j,k,l;
 printf("Enter the size of matrices\n");
 scanf("%d",&l);
 /*first matrix*/
 printf("Enter the Elements of a matrix\n");
 for(i=0;i<l;i++)
 {
 for(j=0;j<l;j++)
 scanf("%d",&a[i][j]);
}
for(i=0;i<l;i++)
 {
 for(j=0;j<l;j++)
 {
 printf("\t%d\t",a[i][j]);
 }
 printf("\n");
 }
 printf("****************");
 /* Second matrix*/
 printf("Enter the Elements of b matrix\n");
 for(i=0;i<l;i++)
 {
 for(j=0;j<l;j++)
 scanf("%d",&b[i][j]);
}
for(i=0;i<l;i++)
 {
 for(j=0;j<l;j++)
 {
 printf("\t%d\t",b[i][j]);
 }
 printf("\n");
 }
/*multiplication*/
 c[0][0]=0;
for(i=0;i<l;i++)
 {
 for(k=0;k<l;k++)
 {
 for(j=0;j<l;j++)
 c[i][k]=c[i][k]+(a[i][j]*b[j][k]);
}
}
 printf("THe result is\n");
 for(i=0;i<l;i++)
 {
 for(j=0;j<l;j++)
 {
 printf("\t%d\t",c[i][j]);
 }
 printf("\n");
 }
system("pause");
 return 0;
 }
Advertisements

Leave a comment

Filed under TUTORIALS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s