How to find the opposite number in C#?

How to find the opposite number in C#? #csharp #dotnet #math

We want to return the opposite number.

Examples:

public static int Opposite(int number) { return -number; }

Solution

Another solution is:

A SO reference:
https://stackoverflow.com/questions/1059480/math-opposite-sign-function

Kata from codewars:
https://www.codewars.com/kata/56dec885c54a926dcd001095/train/csharp

Read more about Math Functions:

These functions can be important if you’re going to work with numbers.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store