Thursday, February 12, 2015
C Program to multiply two matrices
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5][5],b[5][5],c[5][5],m,n,p,q,i,j,k;
clrscr();
printf("Enter rows and columns of first matrix:");
scanf("%d%d",&m,&n);
printf("Enter rows and columns of second matrix:");
scanf("%d%d",&p,&q);
if(n==p)
{
printf("
Enter first matrix:
");
for(i=0;i<m;++i)
for(j=0;j<n;++j)
scanf("%d",&a[i][j]);
printf("
Enter second matrix:
");
for(i=0;i<p;++i)
for(j=0;j<q;++j)
scanf("%d",&b[i][j]);
printf("
The new matrix is:
");
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]=c[i][j]+(a[i][k]*b[k][j]);
printf("%d ",c[i][j]);
}
printf("
");
}
}
else
printf("
Sorry!!!! Matrix multiplication cant be done");
getch();
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.