Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a programusing arrays that will read in an m x n matrix and an n x p matri

ID: 3553926 • Letter: W

Question

  Write a programusing arrays that will read in an m x n matrix and an   n x p matrix and compute the product the two matrices.      Use a file format similar to that used in the previous    assignment. However, since there are two matrices of two    different dimensions, precede each matrix with its    dimensions.    Notes: -----   - Print the two matrices and their product   - Matrix multiplication is just an extension of the      matrix times vector multiplication of the A6_3*.c      examples. The product will produce additional columns      in the result matrix by repeating the process for every      column in the second matrix.          The result of an (m x n) x (n x p) = (m x p) 

Explanation / Answer

#include<stdio.h> int main(){   int a[5][5],b[5][5],c[5][5],i,j,k,sum=0,m,n,o,p; printf(" Enter the row and column of first matrix"); scanf("%d %d",&m,&n); printf(" Enter the row and column of second matrix"); scanf("%d %d",&o,&p);   if(n!=o){     printf("Matrix mutiplication is not possible");       printf(" Column of first matrix must be same as row of second matrix"); }   else{     printf(" Enter the First matrix->");       for(i=0;i<m;i++)       for(j=0;j<n;j++)            scanf("%d",&a[i][j]);       printf(" Enter the Second matrix->");       for(i=0;i<o;i++)       for(j=0;j<p;j++)            scanf("%d",&b[i][j]);       printf(" The First matrix is ");       for(i=0;i<m;i++){       printf(" ");       for(j=0;j<n;j++){            printf("%d ",a[i][j]);       }       }       printf(" The Second matrix is ");       for(i=0;i<o;i++){       printf(" ");       for(j=0;j<p;j++){            printf("%d ",b[i][j]);       }              }       for(i=0;i<m;i++)       for(j=0;j<p;j++)            c[i][j]=0;       for(i=0;i<m;i++){ //row of first matrix       for(j=0;j<p;j++){  //column of second matrix            sum=0;            for(k=0;k<n;k++)                sum=sum+a[i][k]*b[k][j];            c[i][j]=sum;       }       } } printf(" The multiplication of two matrix is ");   for(i=0;i<m;i++){     printf(" ");       for(j=0;j<p;j++){          printf("%d ",c[i][j]);     } }   return 0; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote