Multiplication Of Two Matrices

#include<stdio.h>
#include<conio.h>
void main()
{
int m,n,p,q,a[10][10],b[10][10],c[10][10],i,j,k;
printf("enter the dimensions of matrix A:");
scanf("%d %d",&m,&n);
printf("enter the dimensions of matrix B:");
 scanf("%d %d",&p,&q);
if(n==p)
{
printf("%d elements of first matrix:",m*n);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("%d elements of second matrix",p*q);
for(i=0;i<p;i++)
for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
scanf("the first matrix is:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("the second matrix is :\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
{
c[i][j]+=a[i][k]*b[k][j];
}
    }
}
printf("the resultant matrix is :\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
}
else
printf("matrix multiplication not possible");
getch();
}

Comments

Popular posts from this blog

C program to copy the contents of one file to another

Division of two complex numbers

Student marks by using structures