Question: C++ Need code to multiply 2 arrays and print output with 6 rows and 6 columns The following code below gets matrix data from matrix.txt

C++ Need code to multiply 2 arrays and print output with 6 rows and 6 columns

The following code below gets matrix data from "matrix.txt" (which has numbers in 8 rows and 6 columns) and "matrix2.txt" (which has numbers in 6 rows and 8 columns). I have the code done for reading the data from the files, I just need code to multiply the 2 matrices and print the output. Thanks!!!

#include #include using namespace std;

int main () {

int mult[10][10];

ifstream myfile; myfile.open ("matrix.txt");

cout << "Reading from a file. "; int arr[48]; int k = 0; for (int i = 0; i < 6; ++i) { for (int j = 0; j < 8; ++j) { myfile >> arr[k]; //Read it in a 1D array cout << arr[k] << " "; ++k; } cout << " "; }

ifstream myfile2; myfile2.open ("matrix2.txt");

cout << "Reading from a file. "; int arr2[48]; int k2 = 0; for (int i = 0; i < 6; ++i) { for (int j = 0; j < 8; ++j) { myfile2 >> arr2[k2]; //Read it in a 1D array cout << arr2[k2] << " "; ++k2; } cout << " "; }

// Initializing elements of matrix mult to 0. for(int i = 0; i < 8; ++i) for(int j = 0; j < 6; ++j) { mult[i][j]=0; }

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!