1. Engineering
  2. Computer Science
  3. in c problem subtract 4 to any elements value that...

Question: in c problem subtract 4 to any elements value that...

Question details

in C++

Problem:

Subtract 4 to any element's value that is greater than maxVal.

Ex: If maxVal = 10, then dataPoints = {2, 12, 9, 20} becomes {2, 8, 9, 16}.

------------------------

#include
#include
using namespace std;

int main() {
int maxVal;
int NUM_POINTS;
unsigned int i;
cin >> maxVal;
cin >> NUM_POINTS;
vector dataPoints(NUM_POINTS);

for (i = 0; i < dataPoints.size(); ++i) {
cin >> dataPoints.at(i);
}

/* Your solution goes here */

for (i = 0; i < dataPoints.size(); ++i) {
cout << dataPoints.at(i) << " " ;
}
cout << endl;

return 0;
}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution