Sample Qustion 12

Write a C++ program to multiply 2 arrays of size 3*4 and 4*2.RTead values for 2 arrays from user

     #include <iostream>
    using namespace std;
    int main()
    {
        int a[10][10], b[10][10], mult[10][10], r1, c1, r2, c2, i, j, k;
        cout << "Enter rows and columns for first matrix: ";
        cin >> r1 >> c1;
        cout << "Enter rows and columns for second matrix: ";
        cin >> r2 >> c2;
        while (c1!=r2)
        {
            cout << "Error! column of first matrix not equal to row of second.";
            cout << "Enter rows and columns for first matrix: ";
            cin >> r1 >> c1;
            cout << "Enter rows and columns for second matrix: ";
            cin >> r2 >> c2;
        }
        cout << endl << "Enter elements of matrix 1:" << endl;
        for(i = 0; i < r1; ++i)
            for(j = 0; j < c1; ++j)
            {
                cout << "Enter element a" << i + 1 << j + 1 << " : ";
                cin >> a[i][j];
            }
        cout << endl << "Enter elements of matrix 2:" << endl;
        for(i = 0; i < r2; ++i)
            for(j = 0; j < c2; ++j)
            {
                cout << "Enter element b" << i + 1 << j + 1 << " : ";
                cin >> b[i][j];
            }
        for(i = 0; i < r1; ++i)
            for(j = 0; j < c2; ++j)
            {
                mult[i][j]=0;
            }
        for(i = 0; i < r1; ++i)
            for(j = 0; j < c2; ++j)
                for(k = 0; k < c1; ++k)
                {
                    mult[i][j] += a[i][k] * b[k][j];
                }
        cout << endl << "Output Matrix: " << endl;
        for(i = 0; i < r1; ++i)
        for(j = 0; j < c2; ++j)
        {
            cout << " " << mult[i][j];
            if(j == c2-1)
                cout << endl;
        }
      
        return 0;
    }
 

 download file  cpp file


do you have any qustion please comment



click the advertisement to help for me .... 






Comments

Post a Comment

Popular posts from this blog

Sample Qustion 11

Sample Qustion 1

Sample Qustion 5