C Program for Multiplication of Two Matrices
Get Certified in C Programming and Take Your Skills to the Next Level
Program 1
// Program for Matix Multiplication
#include<stdio.h>
#include<conio.h>
int main()
{
int a1[50][50],b1[50][50],c1[50][50];
int r,c,m,n,k;
printf("\nEnter values of rows and cols\n");
scanf("%d%d",&m,&n);
// Scan first matrix
printf("\nEnter elements in first matrix\n");
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
scanf("%d",&a1[r][c]);
}
}
// Scan second matrix
printf("\nEnter elements in second matrix\n");
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
scanf("%d",&b1[r][c]);
}
}
//Print First matrix
printf("\nFirst matrix: \n");
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
printf("%5d",a1[r][c]);
}
printf("\n");
}
//Print second matrix
printf("\nSecond matrix:\n");
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
printf("%5d",b1[r][c]);
}
printf("\n");
}
// zero to reslut matrix
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
c1[r][c]=0;
}
}
// Multiplication of matrix
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
for(k=0;k<m;k++)
{
c1[r][c]=c1[r][c]+(a1[r][k]*b1[k][c]);
}
}
}
// Print Result Matrix
printf("\nResult matrix:\n");
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
printf("%5d",c1[r][c]);
}
printf("\n");
}
return 0;
}
We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

