Presentation is loading. Please wait.

Presentation is loading. Please wait.

Multi-dimensional Array 1 Multi-dimensional array refers to an array with more than one index. It is a logical representation. On physical storage, the.

Similar presentations


Presentation on theme: "Multi-dimensional Array 1 Multi-dimensional array refers to an array with more than one index. It is a logical representation. On physical storage, the."— Presentation transcript:

1 Multi-dimensional Array 1 Multi-dimensional array refers to an array with more than one index. It is a logical representation. On physical storage, the multi-dimensional array is same as 1D array (stored contiguously in memory space) To define a two-dimensional array, we specify the size of each dimension as follows int seat [30][100];//[row][column] In C++, the array will be stored in the “row-major” order, i.e. first block of memory will be used to store seat[0][0] to seat[0][99], the next block for seat[1][0] to seat[1][99]

2 2

3 Multi-dimensional Array 3 To access an element of the array, we specify an index for each dimension: cin >> seat[y][x];//[row][column] The above statement will input an integer into row - y and column - x of the array. When passing a multi-dimensional array into a function, the size of all dimensions except the first must be specified. The function below can take any two-dimensional integer array with size 100 in the second dimension (size of first dimension is specified in parameter size1 void display (int a[][100], int size1)

4 BMI Program 4 void main() { const int N=10; float data[N][2];// N records, each record holds weight and height int i, position; for (i=0; i<N; i++){ cout << "Weigth(kg) Height(m):"; cin >> data[i][0]; cin >> data[i][1]; } for (i=0; i<count; i++){ cout << "BMI for " << i+1 << “is :”; cout << data[i][0]/(data[i][1]*data[i][1]) << endl; }


Download ppt "Multi-dimensional Array 1 Multi-dimensional array refers to an array with more than one index. It is a logical representation. On physical storage, the."

Similar presentations


Ads by Google