#include<stdio.h>
#include<conio.h>
void main()
{
int a[30][30],b[30][30],c[30][30],i,j,m,n,p,q,k;
printf("Enter the rows and columns of matrix A : ");
scanf("%d%d",&m,&n);
printf("\nEnter the rows and columns of matrix b : \n");
scanf("%d%d",&p,&q);
if(n==p)
{
printf("The matrices can be multiplied.");
printf("\nEnter elements of A:\n");
for (i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("\n Enter elements of B: \n");
for (i=0;i<p;i++)
for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
printf("The product of A and B is: \n");
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\n",c[i][j]);
}
}
getch();
}
No comments:
Post a Comment