Using a 3D array in a program - C++ Data Type

C++ examples for Data Type:Array

Description

Using a 3D array in a program

Demo Code

#include <cstdlib> 
#include <iostream> 

using namespace std; 

int main(int argc, char *argv []) 
{ 
    int thisArray [3][10][5]; 
    int i,j,k; //w  ww. j  a  v a  2  s  .  c  om
    
    i = 0; 
    while (i<3) 
    { 
      j = 0; 
      while (j <10) 
      { 
         k = 0; 
         while (k<5) 
         { 
             thisArray [i][j][k] = (i*j*k) + (i+j +k); 
             k++; 
         } 
         j ++; 
       } 
       i++; 
    } 
    
    i = 0; 
    while (i<3) 
    { 
       j = 0; 
       while (j <10) 
       { 
         k = 0; 
         while (k<5) 
         { 
             cout << thisArray [i][j][k]; 
             if (thisArray [i][j][k]<10) 
             { 
                  cout << " "; 
             } 
             else 
             { 
                 cout << " "; 
             } 
             k++; 
         } 
         j ++; 
         cout << endl; 
        } 
          i++; 
     } 
     return 0; 
}

Result


Related Tutorials