Use nested for loop to display the two dimesional array : multi dimension array « Array « C++ Tutorial






#include <iostream.h>

main()
{
       const int Length=4;

       int *p = new int[Length*Length];
       int a[Length][Length]={{16, 2, 3,13},{ 5,11,10, 8},{ 9, 7, 6,12},{ 4,14,15, 1},};

       for (int i = 0;i < Length; i++)
               for (int j = 0;j < Length; j++)
                       p[ i * Length + j ] = a[ i ][ j ];

       cout<<"display:\n";

       for (int i = 0;i < Length; i++)
       {
               for (int j = 0;j < Length; j++)
                       cout << p[ i * Length + j] <<"  "  ;
               cout << endl;
       }

       delete []p;
       return 0;
}
display:
16  2  3  13
5  11  10  8
9  7  6  12
4  14  15  1








4.4.multi dimension array
4.4.1.Declare a two-dimension array
4.4.2.Initialize a two-dimension array
4.4.3.Creating A Multidimensional Array
4.4.4.Initializing multidimensional arrays
4.4.5.Search a two-dimension array
4.4.6.Use nested for loop to display the two dimesional array
4.4.7.Using pointer notation with a multidimensional array
4.4.8.Fill a two dimensional integer array element by element
4.4.9.how to define, pass, and walk through the different dimensions of an array