code.cpp 381 B

12345678910111213
  1. /* Given a vector, negate all the elements in the vector.
  2. * Negating a positive value -+n will return -n,
  3. * because all +'s are removed.
  4. * Negating a negative value --n will return n,
  5. * because the first - turns the second minus into a +.
  6. */
  7. std::vector<int> negate(std::vector<int> vi) {
  8. for (int dur = 0; dur<vi.size();dur++){
  9. vi[dur] = -vi[dur];
  10. }
  11. return vi;
  12. }