0% found this document useful (0 votes)
16 views

#Include #Include Using Namespace Int Int Int Int For Int For Int

This C++ program defines two 2x2 matrices, multiplies them together using a nested for loop, and stores the result in a third matrix. It then prints out the original matrices and final result matrix.

Uploaded by

Maham Noor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

#Include #Include Using Namespace Int Int Int Int For Int For Int

This C++ program defines two 2x2 matrices, multiplies them together using a nested for loop, and stores the result in a third matrix. It then prints out the original matrices and final result matrix.

Uploaded by

Maham Noor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

#include <conio.h>
using namespace std;
int main()
{
int matrix1[2][2]={{1,2},{3,4}};
int matrix2[2][2]={{5,6},{7,8}};
int resultant[2][2];
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
resultant[i][j]=0;
for (int k = 0; k < 2; k++)
{
resultant[i][j]=resultant[i][j]+(matrix1[i][k]*matrix2[k][j]);
}
}
}
cout<<"First Matrix\n";
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
cout<<matrix1[i][j]<<"\t";
}
cout<<endl;
}
cout<<endl<<endl;
cout<<"second Matrix\n";
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
cout<<matrix2[i][j]<<"\t";
}
cout<<endl;
}
cout<<endl<<endl;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
cout<<resultant[i][j]<<"\t";
}
cout<<endl;
}
getch();
return 0;
}

You might also like