#include using namespace std; const int M = 3; const int N = 3; const int P = 2; int main() { int a[M][N] = { {1, 0, 0}, {0, 1, 0}, {0, 0, 1} }; int b[N][P] = { {2, 3}, {4, 5}, {6, 7} }; int ab[M][P] = { {0, 0}, {0, 0}, {0, 0} }; int i, j, k; // Write the code to compute ab[0][0] (requires 1 for loop) i = 0; j = 0; for (k = 0; k < N; k++) { ab[i][j] += a[0][k] * b[k][0]; } cout << "ab[0][0]:" << endl; cout << ab[i][j] << endl; ab[i][j] = 0; // Write the code to compute ab[2][1] (requires 1 for loop) i = 2; j = 1; for (k = 0; k < N; k++) { ab[i][j] += a[i][k] * b[k][j]; } cout << "ab[2][1]:" << endl; cout << ab[i][j] << endl; ab[i][j] = 0; // Write the code to compute ab[0][j] (requires 2 for loops) i = 0; for (j = 0; j < P; j++) { for (k = 0; k < N; k++) { ab[i][j] += a[i][k] * b[k][j]; } } cout << "ab[0][j]:" << endl; for (j = 0; j < P; j++) { cout << ab[i][j] << " "; ab[i][j] = 0; } cout << endl; // Write the code to compute ab[i][1] (requires 2 for loops) j = 1; for (i = 0; i < M; i++) { for (k = 0; k < N; k++) { ab[i][j] += a[i][k] * b[k][j]; } } cout << "ab[i][1]:" << endl; for (i = 0; i < M; i++) { cout << ab[i][j] << endl; ab[i][j] = 0; } // Write the code to compute ab[i][j] (requires 3 for loops) for (i = 0; i < M; i++) { for (j = 0; j < P; j++) { for (k = 0; k < N; k++) { ab[i][j] += a[i][k] * b[k][j]; } } } cout << "ab[i][j]:" << endl; for (i = 0; i < M; i++) { for (j = 0; j < P; j++) { cout << ab[i][j] << " "; ab[i][j] = 0; } cout << endl; } return (0); }