Displaying every element of a 2D array

This ends up displaying
12341
12341
12341
12341

instead of
12345
12345
12345
12345

Why is this?

1
2
3
4
5
6
7
8
9
10
11
12
13
  #include <iostream>
using namespace std;
int maxtemps[4][5]={{1,2,3,4,5},{1,2,3,4,5},{1,2,3,4,5},{1,2,3,4,5}};
int main()
{
  int row, col;
  for ( int row=0; row<4; row++)
  {
      for ( int col=0 ;col<5; col++)
        cout << maxtemps[col][col] << "\t";
      cout << "\n";
  }
}
Did you mean cout << maxtemps[row][col] << "\t"; instead of cout << maxtemps[col][col] << "\t";?
Topic archived. No new replies allowed.