GoogelAddUnit1

Monday, 16 April 2012

WRITE A C-PROGRAM TO FIND THE MULTIPLICATION OF TWO MATRICES OF SIZE M*P&P*N.

WRITE A C-PROGRAM TO FIND THE MULTIPLICATION OF TWO MATRICES OF SIZE M*P&P*N.
AIM:A program tofind the multiplication of the two matrices of size m*p,p*n.
PROGRAM:
#include<stdio.h>
main()
{
int a[10][10],b[10][10],c[10][10],i,j,k,m,n,p;
printf("enter the values of m,n,p");
scanf("%d%d%d",&m,&n,&p);
printf("enter the elements of matrix a");
for(i=0;i<m;i++)
for(j=0;j<p;j++)
scanf("%d",&a[i][j]);
printf("enter the elements of matrix b");
for(i=0;i<p;i++)
for(j=0;j<n;j++)
scanf("%d",&b[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
c[i][j]=0;
for(k=0;k<p;k++)
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
printf("the multiplication matrix is =%d",c[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
printf("%d",c[i][j]);
printf("\n");
}
}
OUTPUT:
enter the values of m,n,p
 2,2,2
enter the elements of matrix a
1 2 3 4
enter the elements of matrix b
1 0 0 1
the multiplication matrix is
1 2 3 4

No comments:

Post a Comment