Output Matrix 2x3 Array & its Transpose 3x2 Matrix Array

I have this problem that requires me to have an user input 6 numbers. Then cout these numbers of an array of size = 6 to print out as follow:
6 5 4
3 2 1

Then must cout its transpose and should look as follow:
6 3
5 2
4 1

I so far have first part done, but cant come up with correct coding for the transpose. Here is what I have so far

------------------------------------------------------
/* This program will take a matrix and make it a transpose matrix */

#include <iostream>
using namespace std;

const int size = 6;
double matrix_M [size] , matrix_T [size];

void transpose();

int main()
{
matrix_M [size] = matrix_T [size];
cout << " Enter 6 numbers of a Matrix: ";
for (int i=0; i<6 ; i++ )
{
cout << "\t";
cin >> matrix_M [i]; //input the #s in array as: myArr[0], myArr[2], ... , myArr[4]
}

cout << "\n\n *********************";
cout << "\n Here is the Matrix M: \n";
cout << " *********************\n";
for (int row1 = 0; row1 < 3; row1++) //outputs the 1st row
cout << " " << matrix_M [row1] << "\t";
cout << "\n\n";
for (int row2 = 3; row2 < 6; row2++) //outputs the 2nd row
cout << " " << matrix_M [row2] << "\t" ;
cout << "\n\n";

transpose();

cout << "\n\n\n\n\t\t\t";
system ("pause");
return 0;
}

void transpose()
{
for ( int a = 0; a < 3; a ++ )
{
for ( int b = 3; b < 6; b++ )
{
cout << matrix_T [b][a];
}
}


}
Last edited on
find the row and col of the number in matrix and switch them:
1
2
3
4
5
int i;//the index of matrix element
int row = i%3;
int col = i/3;
int t = col + row*2;
transpose[t] = matrix[i]
I dont understand how to change the current code...to what you have wrote ?
1
2
3
4
5
6
7
8
9
10
void transpose(){
    for(int i = 0; i < 6; i++){
        //my code above
    }
    for(int t = 0; t < 6; t++){
        cout << transpose[i];
        if(t%2 == 1) cout << '\n';//new line when t = 1, 3, 5
        else cout << ' ';//space otherwise
    }
}
Hi, perfect...that works...thanks a lot
Topic archived. No new replies allowed.