Saturday, February 13, 2021

How to write a program of Matrix Multiplication in 'C'

   Write a C-program using  two dimensional  array given two matrix scan and print then show the two matrix sum and multiplication. 

Program of Matrix  Sum & Multiplication in 'C' 

#include<stdio.h>

main(){

int a[20][20], b[20][20], d[20][20], e[20][20], i, j, n, m, k, m1, n1;

printf(" Enter the value of row m and column n = ");

scanf("%d %d", &m, &n);

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

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

printf(" Enter %d %d entris = ", i+1, j+1);

scanf("%d", &a[i][j]);

}

}

printf(" The matrix A = \n");

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

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

printf("  %d ", a[i][j]);

}

printf("\n");

}

printf(" Enter the value of second matrix row m1 and column n1 = ");

scanf("%d %d", &m1, &n1);

for(i=0; i<m1; i++){

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

printf(" Enter %d %d entris = ", i+1, j+1);

scanf("%d", &b[i][j]);

}

}

printf(" The matrix B = \n");

for(i=0; i<m1; i++){

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

printf("  %d ", b[i][j]);

}

printf("\n");

}

if(m==m1 && n==n1){

printf(" Sum of two matrix\n");

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

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

e[i][j] = a[i][j] + b[i][j];

printf("  %d ", e[i][j]);

}

printf("\n");

}

    }

    else

    printf(" Matrix addtion not possible\n");

if(n==m1){

printf(" Product of two matrix\n");

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

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

d[i][j]=0;

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

d[i][j] = d[i][j]+ a[i][k] * b[k][j];

}

printf("  %d ", d[i][j]);

}

printf("\n");

}

printf("\n");

  }

  else

  printf(" Matrix multiplaction not possible");

}

mathextention

Author & Editor

Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.

0 comments:

Post a Comment