First time here? Checkout the FAQ!
x
menu search
brightness_auto
more_vert

Write a C program to perform multiplication of two matrices.

thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike

1 Answer

more_vert
 
verified
Best answer
#include<stdio.h>
#include<conio.h>
int main(){
 int a[10][10],b[10][10],mul[10][10],r,c,i,j,k;
// clrscr();
 printf("enter the number of row=");
 scanf("%d",&r);
 printf("enter the number of column=");
 scanf("%d",&c);
 printf("enter the first matrix element=\n");
 for(i=0;i<r;i++)
{
 for(j=0;j<c;j++)
 {
 scanf("%d",&a[i][j]);
 }
}
 printf("enter the second matrix element=\n");
 for(i=0;i<r;i++)
{
 for(j=0;j<c;j++)
 {
 scanf("%d",&b[i][j]);
 }
}

printf("multiply of the matrix=\n");
for(i=0;i<r;i++)
{
 for(j=0;j<c;j++)
 {
 mul[i][j]=0;
 for(k=0;k<c;k++)
 {
 mul[i][j]+=a[i][k]*b[k][j];
 }
 }
}
//for printing result
 for(i=0;i<r;i++)
{
 for(j=0;j<c;j++)
{
 printf("%d\t",mul[i][j]);
 }
 printf("\n");
}
 return 0;
 getch();
} 
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
more_vert
for addition just change this line
 mul[i][j]+=a[i][k]*b[k][j];

to

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


and if you want you can change mul to sum
...