Initialize a two-dimension array : multi dimension array « Array « C++ Tutorial






#include <iostream> 
using namespace std; 
 
 int main() 
{ 
  int i, j; 
  int sqrs[10][2] = { 
    {1, 1}, 
    {2, 4}, 
    {3, 9}, 
    {4, 16}, 
    {5, 25}, 
    {6, 36}, 
    {7, 49}, 
    {8, 64}, 
    {9, 81}, 
    {10, 100} 
  }; 
 
  cout << "Enter a number between 1 and 10: "; 
  cin >> i; 
 
  // look up i 
  for(j=0; j<10; j++)  
    if(sqrs[j][0]==i) break; 
  cout << "The square of " << i << " is "; 
  cout << sqrs[j][1]; 
 
  return 0; 
}
Enter a number between 1 and 10: 7
The square of 7 is 49








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