C Program to Multiply Two Matrices
#include<stdio.h> #include<conio.h> #include<math.h> void main(){ int a[15][15],b[15][15],c[15][15],k,n,i,j,l,m; clrscr(); printf("How many rows and columns of A Matrix you want to give ?"); scanf("%d%d",&k,&n); printf("Enter the value of A matrix :"); for(i=0;i<k;i++) for(j=0;j<n;j++) scanf("%d",&a[i][j]); printf("How many rows and columns of A Matrix you want to give ?"); scanf("%d%d",&n,&l); printf("Enter the value of B matrix :"); for(i=0;i<n;i++) for(j=0;j<l;j++) scanf("%d",&b[i][j]); for(i=0;i<k;i++) for(j=0;j<l;j++) { c[i][j]=0; for(m=0;m<n;m++) c[i][j]=c[i][j]+a[i][m]*b[m][j]; } printf("The multiplication of Matrix is :"); for(i=0;i<m;i++) { for(j=0;j<l;j++) printf("%5d",c[i][j]); printf("\n"); } getch(); }
Output: