fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. const int MAX_ELEMENTS = 20; // Number of input integers
  6. int userVals[MAX_ELEMENTS]; // Array to hold the user's input integers
  7. int i, count; // <-- ADD count!
  8.  
  9. cin >> count; // <-- ADD THIS!
  10.  
  11. for (i = 0; i < count; ++i) { // <-- use count, not MAX_ELEMENTS!
  12. cin >> userVals[i];
  13. }
  14.  
  15. for (i = count - 1; i >= 0; --i) { // <-- use count, not MAX_ELEMENTS!
  16. cout << userVals[i] << " ";
  17. }
  18.  
  19. cout << endl;
  20. return 0;
  21. }
Success #stdin #stdout 0.01s 5396KB
stdin
5 2 4 6 8 10 
stdout
10 8 6 4 2