0% found this document useful (0 votes)
31 views1 page

Matrix Multiplication in C Program

The document contains a C program that performs matrix multiplication. It prompts the user to input the dimensions and elements of two matrices, checks if multiplication is possible, and computes the resulting matrix if applicable. If the matrices cannot be multiplied due to incompatible dimensions, it notifies the user accordingly.

Uploaded by

apurbabarman.mtb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views1 page

Matrix Multiplication in C Program

The document contains a C program that performs matrix multiplication. It prompts the user to input the dimensions and elements of two matrices, checks if multiplication is possible, and computes the resulting matrix if applicable. If the matrices cannot be multiplied due to incompatible dimensions, it notifies the user accordingly.

Uploaded by

apurbabarman.mtb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

/*To find the Matrix multiplication*/

#include<stdio.h>
main ()
{
int i,j,k,m1,n1,m2,n2,sum=0;
int a[10][10],b[10][10],c[10][10];

printf("Enter the order of the first matrix A\n");


scanf("%d%d",&m1,&n1);

printf("Enter the elements of the first matrix A row-wise\n");


for(i=0;i<m1;i++)
for(j=0;j<n1;j++)
scanf("%d",&a[i][j]);

printf("Enter the order of the 2nd matrix B\n");


scanf("%d%d",&m2,&n2);

printf("Enter the elements of the 2nd matrix B row-wise\n");


for(i=0;i<m2;i++)
for(j=0;j<n2;j++)
scanf("%d",&b[i][j]);

if(n1==m2)
{
for(i=0;i<m1;i++)
{
for(j=0;j<n2;j++)
{
for(k=0;k<n1;k++)
sum=sum+a[i][k]*b[k][j];
c[i][j]=sum;
sum=0;
}
}

printf("The required matrix is\n");


for(i=0;i<m1;i++)
{
for(j=0;j<n2;j++)
printf("%d ",c[i][j]);
printf("\n");
}
}
else
printf("Matrix multiplication is not possible\n");

printf("\nThis program is written by Dr. Sourav Kar");


printf("\nPress any key to exit.\n");
}

You might also like