C program :
#include <stdio.h>
int main ()
{
int a[' '][' '],b[' '][' '],d[' '][' '];
int i,sum,j,k,r,c,R,C;
printf("enter the size of row for first matrix:");
scanf("%d",&r);
printf("enter the size of column for first matrix:");
scanf("%d",&c);
for (i=0;i<r;i++)
{
for (j=0;j<c;j++)
{
printf("Enter a[%d][%d]: ",i,j);
scanf("%d",&a[i][j]);
}
}
printf("enter the size of row for second matrix :");
scanf("%d",&R);
printf("enter the size of column for second matrix :");
scanf("%d",&C);
for (i=0;i<R;i++)
{
for (j=0;j<C;j++)
{
printf("Enter b[%d][%d]: ",i,j);
scanf("%d",&b[i][j]);
}
}
printf("\n printing the first multi dimentional array....\n");
for(i=0;i<r;i++)
{
printf("\n");
for (j=0;j<c;j++)
{
printf("%d\t",a[i][j]);
}
}
printf("\n printing the second multi dimentional array....\n");
for(i=0;i<R;i++)
{
printf("\n"); for (j=0;j<C;j++)
{
printf("%d\t",b[i][j]);
}
}
if(R != c)
{
printf("\n Multiplication not possible");
}
else
{
for (i = 0; i <= R-1; i++)
{
for (j = 0; j <= C-1; j++)
{ sum = 0;
for (k = 0; k <= R-1; k++)
{
sum = sum + a[i][k] * b[k][j];
}
d[i][j] = sum;
}
}
printf("\nMultiplication Of Two Matrices : \n");
for (i = 0; i < R; i++)
{ for (j = 0; j < C; j++)
{ printf(" %d ", d[i][j]);
}
printf("\n");
}
}
return 0;
}
Comments