What is Multi Dimensional Array in C Programming ?

3d array in c

In this article we will be going to discuss about Multi-Dimensional Array in C in which following topics are included,

  • Multi-Dimensional Array in C
  • Syntax of Multi Dimensional Array in C
  • Example Multi-Dimensional Array in C 

Multi-Dimensional Arrays in C:

A Multi-Dimensional Array in C is nothing but, it is also an array with more than one dimension such array is know as multi-dimensional array in C. Two-Dimensional Array and Three-Dimensional Array is also treat as Multi-Dimensional Array in C, the exact limit of multi-dimensional array is determined by the compiler.

Syntax of Multi-Dimensional Array:

The general from of a multi-dimensional array in C

datatype array_name[n1][n2][n3].....[n];

Example:-
               int s1[2][3][5];
               int s2[1][2][3][5]...........[n];

Note:-  In case of multi-dimensional array, if you want take input from user then you have to use nested for loop according to dimension of an array like if the dimension of array is three then we use three for loop and if the dimension of an array is four then we use four for loop for taking input respectively. 

Example of Multi-Dimensional Array:

#include<stdio.h>
int main()
{
  int i,j,k;
  int a[3][3][3];

printf("Enter the element of matrix:\n");
  for(i=0;i<3;i++)
{
    for(j=0;j<3;j++)
   {
     for(k=0;k<3;k++)
      {
       scanf("%d",&a[i][j][k]);
      }
   }
}

printf("Entered element are");

  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
   {
    for(k=0;k<3;k++)
     {
       printf("%d",a[i][j][k]);
     }
   }
  printf("\n");
}
return 0;
}

_____________________________________________________________

multi-dimensional array example
_____________________________________________________________

Post a Comment (0)
Previous Post Next Post