---
title: "Opposite Number, C, CodeWars"
slug: opposite-number-c-codewars
type: evergreen
stime: 2025-01-15 @ 12:00AM
status: growing
certainty: certain
importance: 4
tags: [c, codewars, algorithms]
source: codewars-opposite-number
---

## Problem Statement

```
Very simple, given a number (integer / decimal / both depending on the language), find its opposite (additive inverse).

Examples:

1: -1
14: -14
-34: 34
```

## Chosen Solution

Using the additive inverse property, we know the following:

```
In the integers, every element x has a unique element -x such that:
x + (-x) = 0
```

Now that we know that, we can return the inverse of a number by
multiplying it by -x.

```c
int opposite(int number)
{
  return -number; // use additive inverse property
}
```

[Link To Solution on CodeWars](https://www.codewars.com/kata/reviews/575d9b2389dcbca923000188/groups/68aa6a5c4e86241095c94767)

## Related

- [Opposites Attract, C, CodeWars](opposites-attract-c-codewars.md)
- [Leap, C, Exercism](leap-c-exercism.md)
- [Clock, C++, CodeWars](clock-cpp-codewars.md)
- [Roman Numerals Decoder, C++, Codewars](roman-numerals-decoder-cpp-codewars.md)
- [CodeWars](codewars.md)
- [Exercism](exercism.md)
