Skip to main content

C++ = Two 2x2 ordered matrix multiplication

Create a program which contain M and N matrices with the order of 2x2 then assign them any value After that multiply both matrices and print the result matrix on console.

 Code:

#include <iostream>

using namespace std;

int main()

{

    int m[2][2],n[2][2];

    

    cout<<"Assign values to first matrix : "<<endl;

    

    for (int i=0;i<2;i++)

    {

    for (int j=0;j<2;j++)

    {

    cin>>m[i][j];

}

}

cout<<"Assign values to second matrix : "<<endl;

for (int i=0;i<2;i++)

{

for (int j=0;j<2;j++)

{

cin>>n[i][j];

}

}

int l[2][2]={0};

for (int i=0;i<2;i++)

{

for (int j=0;j<2;j++)

{

for (int k=0;k<2;k++)

{

l[i][j] += m[i][k] * n[k][j];

}

}

}

cout<<"The matrix after multiplication is given below : "<<endl;

for (int i=0;i<2;i++)

{

for (int j=0;j<2;j++)

{

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

}

cout<<endl;

}

return 0;

}

Result:



Comments

Popular posts from this blog

C++ = Code for checking any digit palindrome number

Code no: 1 = Using only main function to perform task. #include <iostream> using namespace std; int main() { int number,original,digit,reverse=0; cout<<"Enter any number : "; cin>>number; original=number; while (number!=0) { digit=number%10; reverse=(reverse*10)+digit; number=number/10; } if (original==reverse) { cout<<"This "<<original<<" is Palindrome number."; } else { cout<<"The "<<original<<" is not Palindrome number."; } } Result: Code no: 2 = Using two functions to perform same task. #include <iostream> using namespace std; int isprime(int num) { int digit=0,reverse=0; while (num!=0) { digit=num%10; reverse=(reverse*10)+digit;  num/=10; } return reverse; } int main() { int num; cout<<"Enter any digit to find its sum = "; cin>>num;          int original=num;          if (i...

C++ = Printing diamond with asterik

 CODE: #include <iostream> using namespace std; int main() {     for (int i=1;i<=5;i++)     {     for (int j=1;j<=5-i;j++)     {     cout<<" "; }     for (int k=1;k<=(2*i)-1;k++)     {     cout<<"*"; }   cout<<endl; } for (int i=4;i>=1;i--)     { for (int j=1;j<=5-i;j++)     {     cout<<" "; }     for (int k=1;k<=(2*i)-1;k++)     {     cout<<"*"; }        cout<<endl; } return 0; } RESULT:

C++ = How to sum of digits of any number code.

Code no: 1 = By using array.  #include <iostream> using namespace std; int main()  { int number; cout<<"Enter the n"; cin>>number; int a[number]; int sum=0; cout<<"Enter a digit : "<<endl; for (int i=1;i<=number;i++) { cin>>a[i]; } for (int i=1;i<=number;i++) { sum+=a[i]; } cout<<"The sum of the number : "<<sum; return 0; } Result: Code no: 2 = By using some logic without using array and all the code is in one function. #include <iostream> using namespace std; int main() { int num,origional,sum=0,digit=0; origional=num; cout<<"Enter any no: to finds its sum = "; cin>>num; while(num!=0) { digit=num%10; sum+=digit;  num/=10;  } cout<<"The sum of the digits is "<<sum; return 0; } Result: Code no: 3 = Using same code as of code no: second but using different function to perform same ta...