Write a c ++ program that reads unknown number of integers from the user and stores them into a vector. The user will indicate the end of numbers by entering a 0. The program should then print out these numbers in reverse order.

Respuesta :

tonb

Answer:

#include <iostream>

#include <vector>

using namespace std;

int main() {

vector<int> numberlist;

int number;

while (1) {

 cout << "Enter a number: ";

 cin >> number;

 if (number == 0) break;

 numberlist.push_back(number);

};

reverse(numberlist.begin(), numberlist.end());

for (int number : numberlist) {

 cout << number << " ";

}

return 0;

}

Explanation:

There is a built-in function to reverse the contents of a vector.