ProAnswers.org

Write a C program to perform Matrix Multiplication ?

#include

#include 

void main() 

{ 

int a[10][10],b[10][10],c[10][10],r1,r2,c1,c2,i,j,k; 

clrscr(); 

printf(“enter the no.of rows and columns for 1st matrix:

”);

scanf(“%d%d”,&r1,&c1); 

printf(“enter the values of 1st matrix:

”);

for(i=0;i

{ 

for(j=0;j

scanf(“%d”,&a[i][j]); 

} 

printf(“enter the no.of rows and columns for 2nd matrix:

”);

scanf(“%d%d”,&r2,&c2); 

printf(“enter the values of 2nd matrix:

”);

for(i=0;i

{ 

for(j=0;j

scanf(“%d”,&b[i][j]); 

} 

if(c1==r2) 

{ 

for(i=0;i

{ 

for(j=0;j

{ 

c[i][j]=0; 

for(k=0;k

{ 

c[i][j]=c[i][j]+a[i][k]+b[k][j]; 

} 

} 

} 

printf(“resultant matrix is:

”);

for(i=0;i

{ 

for(j=0;j

{ 

printf(“%d	”,c[i][j]); 

} 

printf(“

”);

} 

} 

else 

printf(“the matrix are not multiplied”); 

getch(); 

} 

Output: 

enter the no.of rows and columns for 1st matrix: 

3 

3 

enter the values of 1st matrix: 

1 

1 

1 

1 

1 

1 

1 

1 

1 

enter the rows and columns for 2nd matrix: 

3 

3 

enter the values of 2nd matrix: 

1 

1 

1 

1 

1 

1 

1 

1 

1 

resultant matrix is: 

3 3 3 

3 3 3 

3 3 3