// Create a 2-D array of size 3 by 3 with user defined values.
// Copy this array in another array of the same size.
// Display both arrays.
#include<iostream.h>
void main()
{
int a[3][3], b[3][3], i, j, zero = 0;
// initializing 2 D array a with user defined values
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<"enter value for a["<<i<<"]["<<j<<"]:";
cin>>a[i][j];
}
}
cout<<endl;
//displaying array a
cout<<"displaying array a:"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
// copyinh 2 D array a to b
cout<<"copying array:"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[i][j] = a[i][j];
}
}
//displaying array b
cout<<"displaying array b:"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<b[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
}
// Copy this array in another array of the same size.
// Display both arrays.
#include<iostream.h>
void main()
{
int a[3][3], b[3][3], i, j, zero = 0;
// initializing 2 D array a with user defined values
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<"enter value for a["<<i<<"]["<<j<<"]:";
cin>>a[i][j];
}
}
cout<<endl;
//displaying array a
cout<<"displaying array a:"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
// copyinh 2 D array a to b
cout<<"copying array:"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[i][j] = a[i][j];
}
}
//displaying array b
cout<<"displaying array b:"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<b[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
}
0 comments:
Post a Comment