알고리즘 17 - Invert values

1576 단어 CodewarsalgorithmCC

Q.

Given a set of numbers, return the additive inverse of each. Each positive becomes negatives, and the negatives become positives.

invert([1,2,3,4,5]) == [-1,-2,-3,-4,-5]
invert([1,-2,3,-4,5]) == [-1,2,-3,4,-5]
invert([]) == []
Notes:
All values are greater than INT_MIN
The input should be modified, not returned.

A)

#include <stddef.h>

void invert(int *values, size_t values_size) {
  for (size_t i = 0; i < values_size; i++)
    values[i] *= -1;
}

좋은 웹페이지 즐겨찾기