Lesson 1c Multidimensional Arrays

Topics: Array, The Elements, Element Pages: 4 (396 words) Published: January 10, 2015
Lesson 1b
MULTIDIMENSIONAL ARRAYS
Multidimensional arrays concept is much the same as one-dimensional arrays, except that the array values in a multidimensional array will store the data as table of values in rows and columns.

Declaring 2-dim array:
int twoArr[3][4];
twoArr is an array of integer with 3 rows and 4 columns
twoArr has 12 elements (4 elements per row).

the subscript of 2-dim array start with 0 for the row
and 0 for the column
the second subscript (column) increase most rapidly
Accessing 2-dim array elements:
twoArr[0][0] = 1twoArr[0][1] = 2twoArr[0][2] = 3twoArr[0][3] = 4 twoArr[1][0] = 5twoArr[1][1] = 6twoArr[1][2] = 7twoArr[1][3] = 8 twoArr[2][0] = 9twoArr[2][1] = 10twoArr[2][2] = 11twoArr[2][3] = 12

Initializing 2-dim array values:
int twoArr[3][4] = {1,2,3,4,5,6,7,8,9,10,11,12};
int twoArr[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}};

int twoArr[3][4] = {1,2,3,4,5,6,7,8,9};

int twoArr[3][4] = {{1,2,3},{4,5,6},{7,8,9}};

Sample Programs:
Inputting and Outputting 2-dim array values
#include
#include

main()
{
int number[3][3];
int x, y;
printf("Enter 9 integer values: ");
for(x=0; x the array for(x=0; x
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Arrays Essay
  • Arrays Essay
  • Lesson Plan Research Paper
  • Essay on The Lesson
  • the lesson Essay
  • Essay about The Lesson
  • The Lesson Essay
  • The Lesson Essay

Become a StudyMode Member

Sign Up - It's Free