Two Dimensional Arrays
-
Sometimes we
need to store the data where more than one dimensions are involved, like sales
information of a company, or for mathematical calculations we need to use
matrix.
-
To declare a
two-dimensional integer array of size i,j, you would write something as follows:
-
Syntax:
Data-Type Variable-Name[row-size][col-size];
Where , Data-Type may
be int, char or float,
Variable-Name
represents name of the array,
Row-size indicate the
number of row in table,
Col-size indicate the
number of columns in an array.
-
Example:
int matrix[3][3];
-
In above
example, int is a datatype and matrix is an array name. Here, the size of row
is 3 and size of column is 3.
In above figure, the cell a[i][j] refers to the cell in ith row jth column.
So,
matrix[0][0]=10,
matrix[1][0]=20,
matrix[2][0]=30,
matrix[0][1]=40,
matrix[1][1]=50,
matrix[2][1]=60,
matrix[0][2]=90,
matrix[1][2]=80,
matrix[2][2]=70,
and
like that.
So
, solving mathematical problems involving matrices, we can use two dimensional
array.
No comments:
Post a Comment