Saturday, April 10, 2021

20.50. Write a program that multiplies two matrices.

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>  
void main()

int i, j, rl, cl, r2, c2, *a[10][10], 
*b[10] [10], *c[10] [10];

clrscr ();

for(i=0; i<10; i++)
{
a[i]=(int *)malloc(sizeof(char)*10);
b[i]=(int *)malloc(sizeof(char)*10);
c[i]=(int *)malloc(sizeof(char)*10);
}

printf ("How many row in A: "); 
scanf("%d", &rl); 
printf ("How many column in A: ");
scanf ("%d", & cl);


for (i=0; i<rl; i++)
for (j=0; j<cl; j++) 
scanf ("%d", (*(a+i)+j);
printf ("How many row in A: "); 
scanf("%d", &r2); 
printf ("How many column in A: ");
scanf ("%d", & c2);

for (i=0; i<r2; i++)
for (j=0; j<c2; j++) 
scanf ("%d", (*(b+i)+j);

if(c1==c2)

{
for (i=0; i<r1; i++)
for (j=0; <c2; j++) 
{

*(*d(d+i)+j)=0;
for(k=0;k<c1;k++)
*(*(d+i)+j)=*(*(d+i)+j)+*(*a+i)+k)**(*(b(+k)+j)

}

printf ("The multiplication of A and B is: ");
for (i=0; i<rl; i++) 
{
for (j=0; j<c2; j++)
printf ("%4d", *(*d+i)+j));
printf("\n");
}
}
else
printf("\nThe multiplication of A and B is impossible.");
getch();
}

No comments:

Post a Comment