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

C++ examples for Data Type:Array

Description

Using a 2D array in a program

Demo Code

#include <cstdlib> 
 #include <iostream> 

 using namespace std; 

 int main(int argc, char *argv []) 
 { //ww w  .  ja  v  a 2  s.  co m
     int thisArray [3][10]; 
     int i,j ; 

     i = 0; 
     while (i<3) 
     { 
        j = 0; 
        while (j <10) 
        { 
            thisArray [i][j] = (i*j) + (i+j); 
             j ++; 
        } 
        i++; 
      } 

      i = 0; 
      while (i<3) 
      { 
         j = 0; 
         while (j <10) 
         { 
              cout << thisArray [i][j]; 
              if (thisArray [i][j]<10) 
              { 
                  cout << " "; 
              } 
              else 
              { 
                  cout << " "; 
              } 
              j ++; 
          } 
          cout << endl; 
           i++; 
       } 
       return 0; 
}

Result


Related Tutorials