8.2.2 Data Structures (2D Arrays) Flashcards
What are NESTED FOR LOOPS? Give an example
Explain 2D Arrays
What happens when a 2D array is declared in Pseudocode?
2D Arrays in Pseudocode
INTEGER table[5, 3]
DECLARE table : ARRAY[0:4, 0:2] OF INTEGER
// assigning a value to first element in 2D array
table[0, 0] = 27;
// assigning a value to last element in table
table[4, 2] = 21;
// Declaring and initialising an array
INTEGER table [5,3] = { { 24, 32, 13 },
{ 61, 26, 17 },
{ 13, 44, 99 },
{ 37, 81, 17 },
{ 09, 54, 86 } };
// Output each element of a 2D array
FOR row ← 0 TO 4 STEP 1
FOR col ← 1 TO 2 STEP 1
OUTPUT table[row,col]
NEXT row
NEXT col
// Storing input into a 2D array
FOR row ← 0 TO 4 STEP 1
FOR col ← 1 TO 2 STEP 1
INPUT table[row,col]
NEXT row
NEXT col