School-Coding-Cpp/array/elimina_pari_vettori.cpp

39 lines
849 B
C++

/*
AUTORE: Vichingo455
The program deletes peer numbers from a vector without using memmove
*/
#include <iostream>
#include <array>
#include <vector>
#include <cstdlib>
using namespace std;
void printVector(const vector<int> & vett) {
for (int i = 0; i < vett.size(); i++)
cout << vett.at(i) << " ";
cout << endl;
}
void deletePeers(vector<int> & vett) {
for (int i = 0; i < vett.size(); i++) {
if (vett.at(i) % 2 == 0) {
vett.erase(vett.begin() + i);
}
}
}
int main() {
vector<int> vett;
int vectorSize;
cout << "Insert the size of the vector: ";
cin >> vectorSize;
cout << endl;
for (int i = 0,value; i < vectorSize; i++) {
cout << "Insert a value: ";
cin >> value;
vett.push_back(value);
cout << endl;
}
printVector(vett);
deletePeers(vett);
printVector(vett);
return 0;
}