Array C Programing

Answer: C Language also facilitates the arrays of tree or more dimensions depending on compiler. The multiplication array is controlled by multiple subscripts. We can declare a multidimensional array as follows in general:

datatype array name [size 1], [size 2], [size 3], .......[size n];

In this declaration; [size 1], [size 2]; .....[size n] specify the size of 'n' dimension.

For Example:

int table[3][5][4];

Given Table is a three dimensional array declares to cantain 60 integer type elements. The above array can be represented as :

Multidimensional Array C Programming

C does not specify any limit for array dimension. However most compiler permit 7 to 10 dimensions.

Some allows even more.

Answer:


// C Program to store and print 120 values entered by the user

#include 
int main()
{
	int i, j, k, test[5][4][6];

	printf("Enter 12 values: \n");

	for (i = 0; i < 5; ++i) {
		for (j = 0; j < 4; ++j) {
			for (k = 0; k < 6; ++k) {
				scanf_s("%d", &test[i][j][k]);
			}
		}
	}

	// Printing values with proper index.

	printf("\nDisplaying values:\n");
	for (i = 0; i < 5; ++i) {
		for (j = 0; j < 4; ++j) {
			for (k = 0; k < 6; ++k) {
				printf("test[%d][%d][%d] = %d\n", i, j, k, test[i][j][k]);
			}
		}
	}
}