Read integers from input and store each integer into a vector until 0 is read. Do not store 0 into the vector. Then, output the values in the vector that are not equal to the last value in the vector, each on a new line.

Ex: If the input is -90 -10 22 -10 0, the output is:

-90
22
#include
#include
using namespace std;

int main() {

/* Your code goes here */

return 0;
}

Respuesta :

Answer:

The program is as follows:

#include<iostream>

#include<vector>

using namespace std;

int main() {

vector<int> myInputs;

int num;

cin>>num;

while(num !=0){

   myInputs.push_back(num);

   cin>>num;}

for (int i = 0; i < myInputs.size(); i++){

       if(myInputs[myInputs.size()-1]!=myInputs[i]){

           cout << myInputs[i] << " ";        }

       }

return 0;

}

Explanation:

Declare integer vector of elements

vector<int> myInputs;

Declare num for integer inputs

int num;

Get input for num

cin>>num;

This loop is repeated until input is 0

while(num !=0){

Push the input to the vector

   myInputs.push_back(num);

Get another input

   cin>>num;}

Iterate through the vector elements

for (int i = 0; i < myInputs.size(); i++){

For vector elements not equal to the last element

       if(myInputs[myInputs.size()-1]!=myInputs[i]){

The element is printed

           cout << myInputs[i] << " ";        }

       }