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

Write a program that asks the user to input a 3 X 3 matrix of integers, a row at

ID: 3782042 • Letter: W

Question

Write a program that asks the user to input a 3 X 3 matrix of integers, a row at a time
Be sure to identify which row is being requested:
Values:
Row #1: 8 7 9
Row #2: 6 3 12
Row #3: 5 0 10

When the whole matrix is filled, print it out in 3 X 3 matrix format in the console window
Pseudo code:
•   <iostream> & namespace std
•   Main:
o   Out: Print my name
o   Declare data types for 4 counters and the array
o   Nested loop 1:
   Out: asks user for value for row/column
   In: variablename[counter1][counter2]
o   Nested loop 2:
   Out: variablename[counter3][counter4] & some space
   Out: endl;
o   Pause
o   End program

Explanation / Answer

main.cpp

#include <iostream>
using namespace std;

int main()
{
    int a[10][10], r, c, i, j;

    cout << "Enter rows and columns of matrix: ";
    cin >> r >> c;

    // Storing element of matrix entered by user in array a[][].
    cout << endl << "Enter elements of matrix: " << endl;
    for(i = 0; i < r; ++i)
    for(j = 0; j < c; ++j)
    {
        cout << "Enter elements a" << i + 1 << j + 1 << ": ";
        cin >> a[i][j];
    }

    // Displaying the matrix a[][]
    cout << endl << "Entered Matrix: " << endl;
    for(i = 0; i < r; ++i)
        for(j = 0; j < c; ++j)
        {
            cout << " " << a[i][j];
            if(j == c - 1)
                cout << endl << endl;
        }

   return 0;
}

Output:-

Enter rows and columns of matrix: 3

3

Enter elements of matrix:

Enter elements a11: 8

Enter elements a12: 7

Enter elements a13: 9

Enter elements a21: 6

Enter elements a22: 3

Enter elements a23: 12

Enter elements a31: 5

Enter elements a32: 0

Enter elements a33: 10

Entered Matrix:

8 7 9

6 3 12

5 0 10

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