Sunday, 21 January 2018

Program for Matrix Multiplaction | Sample program for Matrix |



Program for Matrix Multiplaction
#include<stdio.h>
#include<conio.h>
main()
{
int a[10][10],b[10][10],c[10][10],i,j,m,n,o,p,k;
clrscr();
printf("input the order of A&B matrice's\n");
scanf("%d%d%d%d",&m,&n,&o,&p);
if(n==o)
{
printf("matrice's can be multiplied\n");
printf("input matrix A\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{

scanf("%d",&a[i][j]);
}
printf("\n");
}
printf("input matrix B\n");
for(i=0;i<o;i++)
{
for(j=0;j<p;j++)
{
scanf("%d",&b[i][j]);
}
printf("\n");
}
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
                        printf("%5d",c[i][j]);

}
printf("\n");
}
}
else
printf("matrice's cannot be multiplied");
getch();
}

0 comments:

Post a Comment