简体   繁体   中英

How would i go about multiplying a number by a -1 in C?

i want to do this because i don't want to output a negative number. So i'd like to multiply it by -1 to make it positive. Thanks in advance.

There's a function called abs that gives you that:

int x = -1;
int y = abs(x);

It effectively gives you the number without the sign, or the "absolute value" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM