Skip to content

Instantly share code, notes, and snippets.

@gu-mi
Last active December 11, 2015 06:09
Show Gist options
  • Save gu-mi/4557638 to your computer and use it in GitHub Desktop.
Save gu-mi/4557638 to your computer and use it in GitHub Desktop.
Using nested loops to iterate elements in a 2-dim array of integers
#include <iostream>
using namespace std;
int main()
{
const int MAX_ROWS = 3;
const int MAX_COLS = 4;
// 2-D array of integers
int MyInts[MAX_ROWS][MAX_COLS] = { {34, -1, 879, 22},
{24, 365, -101, -1},
{-20, 40, 90, 97} };
// iterate rows, each array of int
for (int Row = 0; Row < MAX_ROWS; Row++)
{
// iterate integers in each row (columns)
for (int Column = 0; Column < MAX_COLS; Column++)
{
cout << "Integer[" << Row << "][" << Column \
<< "] = " << MyInts[Row][Column] << endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment