Multiply Two Dimensional Array Using C++
========================================================================
#include<iostream>
using namespace std;
main()
{
int arr1[3][3]={{2,3,4},
{4,3,2},
{4,2,2}};//initialize first Array
int arr2[3][3]={{2,2,1},
{1,1,4},
{1,2,3}};//initialize second Array
int res[3][3];// resultant array
int i,j,k;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
res[i][j]=0;//counter array variable ,initialization
for(k=0;k<3;k++)
{
res[i][j]=res[i][j]+(arr1[i][k]*arr2[i][j]);//main logic
}
}
}
cout<<"Resultant Array\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<res[i][j]<<" ";
}
cout<<endl;
}
}
========================================================================
OutPut:
Code By : Kabeer Hussain
0 comments:
Post a Comment