by Dinesh Thakur Category: Array

A three-dimensional array is that array whose elements are two-dimensional arrays. In practice, it may be considered to be an array of matrices. A three-dimensional array with int elements may be declared as below.

int A [m] [n] [p];

Program illustrates the input and output of a three-dimensional array

Illustrates input/output of a three-dimensional array

#include <stdio.h>

int main()
{
  int i,j,k,n,m ,p ;
  int Tom[2] [3] [3];
  clrscr();
  printf("Enter integer elements of Tom[2] [3][3] array:\n");
  /*you may write in any groups, the program will read left to right.*/
  for(i=0; i<2; i++)
   for (j=0; j<3; j++)
    for (k = 0; k<3; k++)
      scanf ("%d", &Tom[i] [j] [k]);
       for( n=0;n<2;n++)
        {
          printf ("\n");
           for( m=0;m<3;m++)
             {
                printf ("\n");
                for(p = 0; p<3; p++)
                 printf ( "%d ", Tom [n] [m] [p] );
             }
        }
           printf ("\n");
            return 0;
}

Three-Dimensional Arrays in C



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles