Create an application that uses two nested for loopsto loop through the 2D array defined above and print the values.
#include <iostream>
using namespace std;
int main()
{
int row,col,a[2][2];
cout<<"Enter elements :";
for(row=0;row<2;row++)
{
for(col=0;col<2;col++)
{
cin>>a[row][col];
}
}
for(row=0;row<2;row++)
{
for(col=0;col<2;col++)
{
cout<<a[row][col]<<" ";
}
cout<<endl;
}
return 0;
}
Write an application that creates a two-dimensional array of doubles, with two rows and three columns. Print the value in the second row and third column.
#include <iostream>
using namespace std;
int main()
{
int row,col,a[2][3];
cout<<"Enter elements :";
for(row=0;row<2;row++)
{
for(col=0;col<3;col++)
{
cin>>a[row][col];
}
}
cout<<"second row and thirder column :"<<a[1][2];
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int i,j,k,a[3][3],b[3][3],c[3][3],d[3][3];
cout<<"Enter elements for 1st array:"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>a[i][j];
}
}
cout<<"Enter elements for 2nd array:"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>b[i][j];
}
}
cout<<"\\n\\nAddition :"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
cout<<c[i][j]<<" ";
}
cout<<endl;
}
cout<<"\\n\\nSubtraction :"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
d[i][j]=a[i][j]-b[i][j];
cout<<d[i][j]<<" ";
}
cout<<endl;
}
cout<<"\\n\\nTranspose of 1st matrix :"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[j][i]<<" ";
}
cout<<endl;
}
cout<<"\\n\\nMultiplication :"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
d[i][j]=0;
for(k=0;k<3;k++)
{
d[i][j]+=a[i][k]*b[k][j];
}
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<d[i][j]<<" ";
}
cout<<endl;
}
}