Ask Question
8 July, 20:10

make 2 dimensional arryas, ask for the rows and columns, then enter the values and then multiply both arrays.

+5
Answers (1)
  1. 8 July, 22:11
    0
    The program of this question can be given as:

    Program:

    #include / /header file.

    using namespace std;

    int main () / /define main method.

    {

    int First_matrix[10][10], Second_matrix[10][10], multiplication[10][10], rows, columns, i, j, k; / /define variable.

    cout<<"Enter the rows of matrix:";

    cin>>rows; / /insert rows.

    cout<<"Enter the columns of matrix:";

    cin>>columns; / /insert columns

    cout<<"Enter elements of first matrix:"<< endl; / /inserting elements of second matrix

    for (i = 0; i < rows; i++)

    {

    for (j = 0; j < columns; j++)

    {

    cin >> First_matrix[i][j];

    }

    }

    cout<< "Enter elements of second matrix:"<< endl; / /inserting elements of second matrix

    for (i = 0; i < rows; i++)

    {

    for (j = 0; j < columns; j++)

    {

    cin >> Second_matrix[i][j];

    }

    }

    / / multiplication of matrix.

    for (i = 0; i < rows; i++)

    {

    for (j = 0; j < columns; j++)

    {

    multiplication[i][j]=0;

    for (k = 0; k < columns; k++)

    {

    multiplication[i][j] = multiplication[i][j] + First_matrix[i][k] * Second_matrix[k][j];

    }

    }

    }

    / / Displaying matrix.

    cout<< "First Matrix: " << endl;

    for (i = 0; i < rows; i++)

    {

    for (j = 0; j < columns; j++)

    {

    cout<<" "<
    }

    cout<
    }

    cout<< "Second Matrix: "<
    for (i = 0; i < rows; i++)

    {

    for (j = 0; j < columns; j++)

    {

    cout<<" "<
    }

    cout<
    }

    //Displaying multiplication of matrix.

    cout << endl << "multiplication of Matrix: " << endl;

    for (i = 0; i < rows; i++)

    {

    for (j = 0; j < columns; j++)

    {

    cout<<" "<
    }

    cout<
    }

    return 0;

    }

    Output:

    Enter the rows of matrix: 2

    Enter the columns of matrix:2

    Enter elements of first matrix: 1

    2

    4

    3

    Enter elements of second matrix:5

    4

    3

    1

    First Matrix:

    1 2

    4 3

    Second Matrix:

    5 4

    3 1

    multiplication of Matrix:

    11 6

    29 19

    Explanation:

    In the above matrix (2-dimensional array) program firstly we insert the rows and columns for creating a user-defined matrix. Then we insert the first matrix by using a loop. In this loop, we used row and column that is inserted by the user. Similarly, we insert the second matrix. then we multiply the matrix. In the multiplication, we define 3 loop that is (i, j, k). first loop (i) work on the rows and the second and third loop (j, k) work on the columns. In the last first we print matrix (first, second). Then we print there multiplication.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “make 2 dimensional arryas, ask for the rows and columns, then enter the values and then multiply both arrays. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers