Home » Sometech » WAP for multiplication of two matrices if first matrix of order m*n (e.g 3*2) second matrix is of order n*p (e.g 2*4) multiplication matrix will be Of order m*p (e.g 3*4).

WAP for multiplication of two matrices if first matrix of order m*n (e.g 3*2) second matrix is of order n*p (e.g 2*4) multiplication matrix will be Of order m*p (e.g 3*4).

#include <stdio.h>

#include<conio.h>

#define S 5

void main()

{

   int i,j,k,m,n,p;

    int A[S][S],B[S][S],C[S][S];

clrscr();

printf(“\nEnter m , n, and p value for matrix order (<= 5) : “);

scanf(“%d%d%d”,&m,&n,&p);

printf(“\nEnter first matrix of order %d * %d : \n”,m,n);

 

for (i = 0; i < m; i++)

 for (j = 0; j < n; j++)

  scanf(“%d”, &A[i][j]);

 

printf(“\nEnter second matrix of order %d * %d : \n”,n,p);

for (i = 0; i < n; i++)

 for (j = 0; j < p; j++)

  scanf(“%d”, &B[i][j]);

 

 

/*multiplication */

printf(“\nResultant matrix of order %d * %d: \n”,m,p);

for (i = 0; i < m; i++)

{   for (j = 0; j < p; j++)

    {

      C[i][j]=0;

     for(k=0;k<n;k++)

       C[i][j]=C[i][j]+A[i][k]*B[k][j];

      printf(“%3d”, C[i][j]);

 

    }

    printf(“\n”);

}

getch();

}

 

Advertisements

SoME Tech

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

%d bloggers like this: