matrix vertically reconfigurated array elements

can somebody please fix it so as to output :
a=
1 5 9
2 6 10
3 7 11
4 8 12

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
#include <iostream>
#include <stdlib.h>
#include <iomanip>

using namespace std;

int main(void)
{
    int i,j,a[4][3],b[4][3]={ {1,2,3}, {4,5,6}, {7,8,9}, {10,11,12} };

    cout <<"b=\n";
    for(i=0; i<4; i++)
    {
        for(j=0; j<3; j++)
        {
            cout << setw(2) << b[i][j] << " ";
        }
        cout << "\n" ;
    }
    cout << "\n\na=\n";
    for(i=0; i<4; i++)
    {

        for(j=0; j<3; j++)
        {
            a[j][i] =  b[i][j];
            cout << setw(2) << a[j][i] << " ";
        }
        cout << "\n" ;
    }
    return EXIT_SUCCESS;
}
Last edited on
Consult your legally-purchased linear algebra book (aka The Internet) and learn how matrix inversion is defined. If you can explain it in words we will help you code it.
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
#include <iostream>

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
    for ( i=0; i<4; i++)
    {
        for( j=0; j<3; j++)
            cout << a[i][j] << " ";
        cout << "\n";
    }
    return 0;
}
Last edited on
more array reconfigurations
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;
}
Topic archived. No new replies allowed.