The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

C Multi Dimensional Array

What Is Multi Dimensional Array?

An array having more than one subscript or dimension is known as multi dimensional array i.e) int arr[3][3]. Multi dimensional arrays are also known as arrays of arrays or matrix.

Syntax - Multi Dimensional Array

• Two Dimensional array requires two subsript variables
• In the following syntax size1 represents no of rows whereas size2 represents no of columns.
Syntax
`data-type varname [size1][size2];`

Why Using Multi Dimensional Array?

Consider a specific example. Suppose that you have a extreme interest in the whether, and you are intent on recording the temperature each day at 2 separate geographical locations throughout the year. After you have sorted out the logistics of actually collecting this information, you can use an array of 2 elements corresponding to the number of locations, where each of these elements in an array of 4 elements to store the temperature values.

Program - Multi Dimensional Array

multi-dimensional-array.c
```#include <stdio.h>
int main()
{
float temp[2][4] = {{12.31, 14.36, 13.4, 12.4}, {11.2, 11.24, 14.2, 12.5}};
int i, j;
for(i = 0; i < 2; i++)
{
for(j = 0; j < 4; j++)
{
printf("\nTemperature @ location %d ---> %f (%d time) ",i+1, temp[i][j] ,j+1);
}
}
return 0;
}```
• Temperature @ location 1 ---> 12.31 (1 time)
• Temperature @ location 1 ---> 14.36 (2 time)
• Temperature @ location 1 ---> 13.4 (3 time)
• Temperature @ location 1 ---> 12.4 (4 time)
• Temperature @ location 2 ---> 11.2 (1 time)
• Temperature @ location 2 ---> 11.24 (2 time)
• Temperature @ location 2 ---> 14.2 (3 time)
• Temperature @ location 2 ---> 12.2 (4 time)

Note:

The above program clearly demonstrates the concept of two dimensional array.

Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report

We to update you