﻿ Two Dimensional Arrays

Two Dimensional Arrays

 Introduction Eight Queens

How cells are referred to using subscript or index notation

 arrayB arrayB arrayB arrayB arrayB arrayB arrayB arrayB arrayB arrayB arrayB arrayB

Horizontal elements beginning with cell identified as arrayB are in row 1

Vertical elements beginning with cell identified as arrayB are in column 2

This array is referred to as a 3x4 array (3 rows and 4 columns)

When listing subscripts or indices the row is given first followed by the column

Rows are in a horizontal line, columns are in a vertical line

Contents of cells

 4 5 8 -3 2 9 1 5 6 7 21 14

The contents of the cells in row 1 are 4, 5, 8, -3

The contents of cells in column 4 are -3, 5, 14

The cell whose subscripts are 1, 2 (arrayB ) holds the value 1

###### #include <iostream>

using namespace std;

###### int main() {     int b = {{1,2}, {3,4}};     for (int i = 0; i < 2; i++)         for (int j = 0; j < 2; j++)             cout << b[i][j]<<endl;     return 0; } ###### #include <iostream>

using namespace std;

###### int main() {     int i, j;     int array1[ 2 ][ 3 ] = { { 1, 2, 3 }, { 4, 5, 6 } },     array2[ 2 ][ 3 ] = { 1, 2, 3, 4, 5 },     array3[ 2 ][ 3 ] = { { 1, 2 }, { 4 } };     cout << "Values in array1 by row are:" << endl;     for ( i = 0; i < 2; i++ )     {     for ( j = 0; j < 3; j++ )         cout << array1[ i ][ j ] << "";     cout << endl;     }     cout << "Values in array2 by row are: " << endl;     for (i = 0; i < 2; i++ )     {         for (j = 0; j < 3; j++ )             cout << array2[ i ][ j ] << "";         cout << endl;     }     cout << "Values in array3 by row are: " << endl;     for ( i = 0; i < 2; i++ )     {         for ( j = 0; j < 3; j++ )             cout << array3[ i ][ j ] << "";         cout << endl;     }     return 0; } 