[英]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.
所以我想将它乘以 -1 使其成为正数。 Thanks in advance.
提前致谢。
There's a function called abs
that gives you that:有一个名为
abs
的函数可以为您提供:
int x = -1;
int y = abs(x);
It effectively gives you the number without the sign, or the "absolute value" .它有效地为您提供没有符号的数字,或“绝对值” 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.