How to output this?

solved
Last edited on
Hello.

The whole code looks valid to me except the fact that makeTranspose function actually does nothing. If your problem is to complete the makeTranspose function, this example might give you a hint:

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
int a[3][3] = 
{
{1, 2, 3},
{1, 2, 3},
{1, 2, 3}
};
int temp[3][3];

// Reserve original value of array "a" to "temp"
for( int i = 0; i < 3; ++i )
{
  for( int j = 0; j < 3; ++j )
  {
    temp[i][j] = a[i][j];
  }
}

// Transposing "a" by moving values in "temp" to "a" in correct sequence.
for( int i = 0; i < 3; ++i )
{
  for( int j = 0; j < 3; ++j )
  {
    a[i][j] = temp[j][i]; // notice that this time, we are giving i, j in different sequence
  }
}


Last edited on
in your transpose function you write a[i][j] = a[i][j]; in line 9. that just overwrites each element with itself

but don't just change it to a[i][j] = a[j][i];. this way the overwritten info is lost. you need to save it in another variable first.


(optional: the diagonal line doesn't need be changed)
Last edited on
Topic archived. No new replies allowed.