C program to find multiplication of two matrices.

#include<stdio.h>
#include<conio.h>
#define r1 3
#define c1 2
#define r2 2
#define c2 3
void main(){
int a[r1][c1],b[r2][c2],m[r1][c2],i,j,k;
clrscr();
printf("Enter Elements of Matirx A:\n");
for(i=0;i<r1;i++){
for(j=0;j<c1;j++){
printf("Enter A[%d][%d] = ",i,j);
scanf("%d",&a[i][j]);
}
}
printf("Enter Elements of Matirx B:\n");
for(i=0;i<r2;i++){
for(j=0;j<c2;j++){
printf("Enter B[%d][%d] = ",i,j);
scanf("%d",&b[i][j]);
}
}
for(i=0;i<r1;i++){
for(j=0;j<c2;j++){
m[i][j]=0;
for(k=0;k<r2;k++){
m[i][j]=m[i][j]+a[i][k]*b[k][j];
}
}
}
printf("Multiplication of matrix A and B is=\n");
for(i=0;i<r1;i++){
for(j=0;j<c2;j++){
printf("%d ",m[i][j]);
}
printf("\n");
}
getch();
}

No comments:

Post a Comment