Two Dimensional Array




Definition of two dimensional array

  • Two dimensional array is an array that has two dimensions, such as row and column.
  • Total number of elements in a two dimensional array can be calculated by multiplication of the number of rows and the number of columns.
  • If there are m rows and n columns, then the total number of elements is m × n, and m × n is called the size of the array.
  • Of course, the data elements of the array will be same type.
  • In mathematics, the two dimensional array is called a matrix and in business it is called table

A two dimensional array can be expressed as follows:




To store and retrieve values in and from array

Data can be stored in a two dimensional array using loop or directly as shown below:
i) storing data taken from keyboard

int B[7][3];
for (int i = 0; i < 7; ++ i)
{
for (int j = 0; j < 3; ++ j)
scanf (“%d”, &B[i][j]);
}


ii) Direct insertion of data in two dimensional array

int B[7][3] = {
{ 1, 2, 3},
{ 9, 10, 11},
… …. ….,
… …. ….,
… …. ….,
… …. ….,
{22, 25, 40}
};


No comments:

Post a Comment

Followers

About Me

Dhaka, Dhaka, Bangladesh
..