0% found this document useful (0 votes)
24 views7 pages

Array (2dim 3dim)

- A two-dimensional array is an array of arrays that organizes multiple lists of data into a single data set. - It is commonly represented as a matrix and is declared with two sets of brackets containing the number of rows and columns (e.g. int score[2][3]). - Each element is accessed using two indices, the first for the row and the second for the column, with the value stored at the intersection of the specified row and column (e.g. score[0][1] = 80).
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views7 pages

Array (2dim 3dim)

- A two-dimensional array is an array of arrays that organizes multiple lists of data into a single data set. - It is commonly represented as a matrix and is declared with two sets of brackets containing the number of rows and columns (e.g. int score[2][3]). - Each element is accessed using two indices, the first for the row and the second for the column, with the value stored at the intersection of the specified row and column (e.g. score[0][1] = 80).
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Two-Dimensional Arrays

–an array of arrays


- a good example to illustrate a two-dimensional
array is a MATRIX w/c is a group of lists, or arrays
that are organized into one data set

syntax:
data-type arrayName[row][col];

Example:
int score[2][3];
Graphical Representation Analogy
Column 0 1 2
10 80 30
0
40 50 90
Row 1
Our two dimensional array score[r][c] is an integer
data type and it ca hold only an integer data with a
maximum of 6 values ([2] x [3]).

➢The row 2 and a maximum of 6 is simply called


2 by 3 (multiplied by 3).

➢The index-number inside the square brackets


are part of the variable name.
Here is the individual value of array variable
score[2][3].
score[0][0] = 10
score[0][1] = 80
score[0][2] = 30
score[1][0] = 40
score[1][1] = 50
score[1][2] = 90

The first index-umber of two dimensional arrays


specifies the maximum row(r), while the second
index-number specifies the maximum column(c).
The value of each array is in between the
intersection of row and column.
The following table illustrates how the
subscripts are specified for this array, w/c
has five (5) rows and four (4) columns.

0 1 2 3
0 [0][0] [0][1] [0][2] [0][3]
1 [1][0] [1][1] [1][2] [1][3]
2 [2][0] [2][1] [2][2] [2][3]
3 [3][0] [3][1] [3][2] [3][3]
4 [4][0] [4][1] [4][2] [4][3]
To initialize these values in the
program:
Column 0 1 2
0 10 80 30
Row 1 40 50 90

int x[2][3]={10,80,30},{40,50,90}};
main ()
{//Declaring an Array; Intialization of 2D Array
int array2D[2][3]={{10,80,30},{40,50,90}};
int i,j;
printf("\n\nA Two Dimensional Array\n\n");
for (j=0; j<2; j++)
{
for (i = 0; i<3; i++)
{// Displaying the Array
printf ("%d ",array2D[j][i]); }
printf("\n");
}
}

You might also like