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
|
// 2D array
#include <iostream>
using namespace std;
int main ()
{
const int numRows = 3; // when making arrays, you need to have consts
const int numCols = 5;
int anArray[numRows][numCols] =
{
{ 1, 2, 3, 4, 5 }, // you had "4, 5, }," when it should have been without the comma after the 5
{ 6, 7, 8, 9, 10 }, // same error as above
{ 11, 12, 13, 14, 15 }
};
for (int i=0;i<3;i++)
{
for (int j=0;j<5;j++)
{
cout << anArray[i][j] << "\t" ;
}
cout << endl;
}
return 0;
}
|