99.6k views
5 votes
PLEASE HELP

HOW DO I DO THIS IN C++
Integers are read from input and stored into a vector until 0 is read. Output the elements from index n to the last index of the vector, where n is specified by the vector's last element. End each number with a newline.

Ex: If the input is 10 16 5 2 0, the vector's last element is 2. Thus, the output is:

5
2

2 Answers

4 votes

Answer:

c++

Step-by-step explanation:

User Maniaque
by
8.2k points
3 votes

Answer:

#include <iostream>

#include <vector>

using namespace std;

int main() {

vector<int> numbers;

int input;

cin >> input;

// Read input until 0 is encountered

while (input != 0) {

numbers.push_back(input);

cin >> input;

}

// Get the last element of the vector

int n = numbers.back();

// Output the elements from index n to the end of the vector

for (int i = n; i < numbers.size(); i++) {

cout << numbers[i] << endl;

}

return 0;

}

Step-by-step explanation:

User Haziz
by
8.5k points

No related questions found