Algorithm 20 - Invert values

Beast from the east·2021년 10월 6일
0

Algorithm

목록 보기
20/27

Q.

Description:
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;
}
profile
Hello, Rabbit

0개의 댓글