write a c program for multiplication of two matrices
/* c program for multiplication of two matrices */
/*author:sai date:7-4-2015 */
#include<stdio.h>
int main()
{
int a[10][10],b[10][10],c[10][10],m,n,p,q,i,j,k;
printf("enter order of first matrix\n");
scanf("%d%d",&m,&n);
printf("enter elements of first matrix\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("enter order of second matrix");
scanf("%d%d",&p,&q);
printf("enter elements of second matrix\n");
for(i=0;i<p;i++)
for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
if(n!=p)
printf("matrix multiplication is not posible\n");
else
for(i=0;i<m;i++)
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<p;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
printf("\t%d",c[i][j]);
printf("\n");
}
}
output :
/* c program for multiplication of two matrices */
/*author:sai date:7-4-2015 */
#include<stdio.h>
int main()
{
int a[10][10],b[10][10],c[10][10],m,n,p,q,i,j,k;
printf("enter order of first matrix\n");
scanf("%d%d",&m,&n);
printf("enter elements of first matrix\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("enter order of second matrix");
scanf("%d%d",&p,&q);
printf("enter elements of second matrix\n");
for(i=0;i<p;i++)
for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
if(n!=p)
printf("matrix multiplication is not posible\n");
else
for(i=0;i<m;i++)
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<p;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
printf("\t%d",c[i][j]);
printf("\n");
}
}
output :
No comments:
Post a Comment