WRITE A C PROGRAM TO MULTIPLY TWO MATRICES - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Sunday, October 30, 2011

WRITE A C PROGRAM TO MULTIPLY TWO MATRICES


WRITE A PROGRAM TO MULTIPLY TWO MATRICES
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
int a[10][10],b[10][10],c[10][10];
int i,j,m,n,p,q,s;
clrscr();
printf("Input row and column of matrix-A\n");
scanf("%d%d",&m,&n);
printf("Input row and column of matrix-B\n");
scanf("%d%d",&p,&q);
if(n!=p)
{
printf("Matrix cannot be multiplied\n");
getch();
exit(0);
}
printf("Input Matrix-A\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Input Matrix-B\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=0;
for(s=0;s<n;s++)


c[i][j]=c[i][j]+a[i][s]*b[s][j];
}
}
printf("\nProduct of matrix A and matrix B is:\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf("\t%d",c[i][j]);
}
printf("\n");
}
getch();
}

No comments:

Post a Comment