WAP for Matrix Multiplication
#include<iostream>
#define MAX 100
using namespace std;
int main()
{
    int a[MAX][MAX], b[MAX][MAX] , c[MAX][MAX];
    int arow , acol, brow, bcol;

    cout<<“Enter the row of matrix A : “;
    cin>>arow; //0-3
    cout<<“Enter the col of matrix A : “;
    cin>>acol;//0-3

    cout<<“Enter the row of matrix B : “;
    cin>>brow;

    cout<<“Enter the row of matrix B : “;
    cin>>bcol;
    if( acol == brow)
    {
        //Matrix A input
        cout<<“Matrix A\n”;
        for( int i = 0; i < arow; i++ )
        {
            for( int j = 0 ; j < acol ; j++)
            {
                cout<<“Enter the element at index [“<<i<<“][“<<j<<“] :”;
                cin>>a[i][j];
            }
        }
        //Matrix b input
        cout<<“Matrix B\n”;
        for( int i = 0; i < brow; i++ )
        {
            for( int j = 0 ; j < bcol ; j++)
            {
                cout<<“Enter the element at index [“<<i<<“][“<<j<<“] :”;
                cin>>b[i][j];
            }
        }

        //Matrix A print
        cout<<“\nMatrix A\n”;
        for( int i = 0; i < arow; i++ )
        {
            for( int j = 0 ; j < acol ; j++)
            {
                cout<<a[i][j] <<” “;
            }
            cout<<endl;
        }
        //Matrix B print
        cout<<“\nMatrix B\n”;
        for( int i = 0; i < brow; i++ )
        {
            for( int j = 0 ; j < bcol ; j++)
            {
                cout<<b[i][j] <<” “;
            }
            cout<<endl;
        }

        //Matrix multi
        int mul = 0;
        for(int i = 0 ; i<arow ; i++)
        {
            for( int j = 0 ; j<bcol ; j++)
            {
                for( int k = 0 ; k <acol ; k++)
                //arow acol | brow bcol
                {
                    mul = mul + (a[i][k] * b[k][j]);
                }
                c[i][j] = mul;
                mul = 0;
            }
        }

        //product matrix print
        cout<<endl;
        for(int i = 0 ; i<arow ; i++)
        {
            for( int j = 0 ; j<bcol ; j++)
            {
                cout<<c[i][j]<<” “;
            }
            cout<<endl;
        }
       

       
    }
    else{
        cout<<“Matrix Multiplication is not possible”;
    }

    return 0;
}
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare