Last active
December 11, 2015 06:09
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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