Read array element from keyboard and output : array read « Array « C++ Tutorial






#include <iostream>
 
 int main()
 {
     int myArray[5];
     for (int i=0; i<5; i++)  // 0-4
     {
         std::cout << "Value for myArray[" << i << "]: ";
         std::cin >> myArray[i];
     }
     for (int i = 0; i<5; i++)
         std::cout << i << ": " << myArray[i] << "\n";
     return 0;
 }
Value for myArray[0]: 1
Value for myArray[1]: 2
Value for myArray[2]: 3
Value for myArray[3]: 4
Value for myArray[4]: 5
0: 1
1: 2
2: 3
3: 4
4: 5








4.2.array read
4.2.1.Read array element one by one from keyboard
4.2.2.Read array element from keyboard and output