matrix multiplication

 // Online C++ compiler to run C++ program online

#include <iostream>

#include <bits/stdc++.h>

using namespace std;


int main() {

    // Write C++ code here

    int p,q,r;

    p=3;

    q=2;

    r=2;

    int mul[p][r];

    for(int i=0;i<p;i++){

        for(int j=0;j<r;j++){

            mul[i][j]=0;

        }

    }

    int arr1[p][q]={{1,2},{3,4},{4,5}};

    int arr2[q][r]={{1,2},{1,2}};

    for(int k=0;k<r;k++){

    for(int i=0;i<p;i++){

        for(int j=0;j<q;j++){

            

               mul[i][k]=mul[i][k]+arr1[i][j]*arr2[j][k]; //00*00=00, 01*

            

            

            

        }

    }

    }

    for(int i=0;i<p;i++){

        for(int j=0;j<r;j++){

            cout<<mul[i][j]<<" ";

        }

        cout<<endl;

    }

}


//////////////////////////

// Online C++ compiler to run C++ program online

#include <iostream>

#include <bits/stdc++.h>

using namespace std;


int main() {

    // Write C++ code here

    int p,q,r;

    p=3;

    q=4;

    r=3;

    int mul[p][r];

    for(int i=0;i<p;i++){

        for(int j=0;j<r;j++){

            mul[i][j]=0;

        }

    }

    int arr1[p][q]={{2,4,1,2},{8,4,3,6},{1,7,9,5}};

    int arr2[q][r]={{1,2,3},{4,5,6},{7,8,9},{4,5,6}};

    for(int k=0;k<r;k++){

    for(int i=0;i<p;i++){

        for(int j=0;j<q;j++){

            

               mul[i][k]=mul[i][k]+arr1[i][j]*arr2[j][k]; //00*00=00, 01*

            

            

            

        }

    }

    }

    for(int i=0;i<p;i++){

        for(int j=0;j<r;j++){

            cout<<mul[i][j]<<" ";

        }

        cout<<endl;

    }

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings