// transpose of array
#include<iostream.h>
void main()
{
int a[3][3], b[3][3], i, j;
// initializing 2 D array a with user defined values
cout<<"Enter values for array A"<<endl<<endl;
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<<endl;
// displaying origional array A
cout<<"Array A ="<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<endl<<endl;
// transpose of array
cout<<"transpose of A:"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[i][j] = a[j][i];
cout<<b[i][j]<<" ";
}
cout<<endl;
}
}
#include<iostream.h>
void main()
{
int a[3][3], b[3][3], i, j;
// initializing 2 D array a with user defined values
cout<<"Enter values for array A"<<endl<<endl;
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<<endl;
// displaying origional array A
cout<<"Array A ="<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<endl<<endl;
// transpose of array
cout<<"transpose of A:"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[i][j] = a[j][i];
cout<<b[i][j]<<" ";
}
cout<<endl;
}
}
0 comments:
Post a Comment