We looked into matrix multiplications in class. I ask you to write a program tha
ID: 3685771 • Letter: W
Question
We looked into matrix multiplications in class. I ask you to write a program that allows for multiplying two matrices. For simplicity, "hard-code" the matrixes and their content so that you have data to work on. In other words, define and initialize the matrices that you are going to use in one step, as we did in class. As it would be too easy to just c&p; some code from the Internet, here are some additional requirements that I ask you to build into your programs. If you submit your programs without implementing the below requirements, you will not receive any points, even if your code is 100% correct! define the macros ROWS, COLS and SHARE and use them consistently whenever the boundaries of the matrixes need to be referenced. Note that SHARE represents the number of columns for the left-hand side matrix, while it represents the number of rows for the right-hand side matrix. likewise, the looping variables that loop through the elements of the matrixes need to be called rows, cols and share, so you need to define the variables rows, cols and share and use them consistentlyExplanation / Answer
Answer for Question:
This below method will perform the matrix multiplication of three by three matrices.
#include<stdio.h>
#define COLS 3
#define ROWS 3
#define SHARE 3
int main(){
int a[COLS][ROWS],b[COLS][ROWS],c[ROWS][COLS],i,j,k,sum=0,m,n,o,p;
printf(" Enter the First matrix->");
for(i=0;i<ROWS;i++)
for(j=0;j<COLS;j++)
scanf("%d",&a[i][j]);
printf(" Enter the Second matrix->");
for(i=0;i<ROWS;i++)
for(j=0;j<COLS;j++)
scanf("%d",&b[i][j]);
printf(" The First matrix is ");
for(i=0;i<ROWS;i++){
printf(" ");
for(j=0;j<COLS;j++){
printf("%d ",a[i][j]);
}
}
printf(" The Second matrix is ");
for(i=0;i<ROWS;i++){
printf(" ");
for(j=0;j<COLS;j++){
printf("%d ",b[i][j]);
}
}
for(i=0;i<ROWS;i++)
for(j=0;j<COLS;j++)
c[i][j]=0;
for(i=0;i<ROWS;i++){ //row of first matrix
for(j=0;j<COLS;j++){ //column of second matrix
sum=0;
for(k=0;k<SHARE;k++)
sum=sum+a[i][k]*b[k][j];
c[i][j]=sum;
}
}
}
printf(" The multiplication of two matrix is ");
for(i=0;i<ROWS;i++){
printf(" ");
for(j=0;j<COLS;j++){
printf("%d ",c[i][j]);
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.