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

How would I display the matrix contents of A and B, in order, for the code below

ID: 3688089 • Letter: H

Question

How would I display the matrix contents of A and B, in order, for the code below? Similar to how matrix C is displayed.

#include<iostream>
#include <fstream>
using namespace std;

int main()

{

ifstream infile;
infile.open ("Multiply.txt");
double A[3][3],B[3][3],C[3][3];
for(int i=0;i<3;i++)
for(int j = 0;j<3;j++)
infile>>A[i][j];
for(int i=0;i<3;i++)
for(int j = 0;j<3;j++)
infile>>B[i][j];
for(int i=0;i<3;i++)
for(int j = 0;j<3;j++)
C[i][j] = A[i][0]*B[0][j] + A[i][1]*B[1][j] + A[i][2]*B[2][j];
for(int i=0;i<3;i++)

{
for(int j = 0;j<3;j++)
cout<<C[i][j]<<" ";
cout<<endl;
}
infile.close();
return 0;
}

Explanation / Answer

#include<iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream infile;
infile.open ("Multiply.txt");
double A[3][3],B[3][3],C[3][3];
for(int i=0;i<3;i++)
for(int j = 0;j<3;j++)
infile>>A[i][j];
for(int i=0;i<3;i++)
for(int j = 0;j<3;j++)
infile>>B[i][j];
for(int i=0;i<3;i++)
for(int j = 0;j<3;j++)
C[i][j] = A[i][0]*B[0][j] + A[i][1]*B[1][j] + A[i][2]*B[2][j];
for(int i=0;i<3;i++)
{
for(int j = 0;j<3;j++)
cout<<C[i][j]<<" ";
cout<<endl;
}

for(int i=0;i<3;i++)
{
for(int j = 0;j<3;j++)
cout<<A[i][j]<<" ";
cout<<endl;
}

for(int i=0;i<3;i++)
{
for(int j = 0;j<3;j++)
cout<<B[i][j]<<" ";
cout<<endl;
}

infile.close();
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