1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int i,j, a[4][3],k=1;
//filling the array -simple case
for ( i=0; i<3; i++)
for( j=0; j<4; j++)
{ a[j][i]=k; k++; }
//showing results
cout << "desired output:|\n";
for ( i=0; i<4; i++)
{
for( j=0; j<3; j++)
cout << setw(2) << a[i][j] << " ";
cout << " |\n";
}
cout << "_______________|";
int b[4][3]={ {1,2,3}, {4,5,6}, {7,8,9}, {10,11,12} };
//depict array's b contents
cout <<"\n\nB=\n";
for(i=0; i<4; i++)
{
for(j=0; j<3; j++)
{
cout << setw(2) << b[i][j] << " ";
}
cout << "\n" ;
}
//vertical rearrangement of the contents
for ( i=0; i<3; i++)
for( j=0; j<4; j++)
b[j][i]=a[j][i];
//show results
cout << "\n\nB'=\n";
for(i=0; i<4; i++)
{
for(j=0; j<3; j++)
cout << setw(2) << b[i][j] << " ";
cout << "\n" ;
}
for(i=0; i<4; i++)
for(j=0; j<3; j++)
a[i][j] = b[i][j];
cout << "\nshowing results: convert B'[4x3] into B'[3x4] array:\n";
//showing results convert a 4x3 into a 3x4 array:
cout << "\nmodified B' =\n";
for(i=0; i<3; i++)
{
for(j=0; j<4; j++)
cout << setw(2) << a[j][i] << " ";
cout << "\n" ;
}
return 0;
}
|