简体   繁体   English

我将如何在 C 中将数字乘以 -1?

[英]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.

相关问题 我 go 如何在 C 中反转二维数组? - How would I go about reversing a 2D array in C? 我将如何检查我在C中工作的文件系统 - How would I go about checking the file system I'm working on in C 如何在C / GTK中不以小部件的形式打开图像? - How would one go about opening an image not as widget in C/GTK? 用C编写一个二维数组表。我将如何去做。 关于整洁(例如分界线) - Writing a 2-dimensional array table in C. How would I go about doing this. About neatness (such as dividing lines) as well 我将如何在&& if语句中使用2个数组 - How would i go about using 2 arrays in an && if statement 我将如何创建自己的VM? - How would I go about creating my own VM? 我将如何为我的语言添加定义? - How would I go about adding definitions to my language? 我将如何编写Linux TTY嗅探器? - How would I go about writing a Linux TTY sniffer? 我将如何使用pthreads使此udpclient异步? - How would I go about making this udpclient asynchronous using pthreads? 在Linux上的C中,我将如何使用2个程序,后者将文本数据发送到使用stdout显示的第一个程序? - In C on Linux, how would I go about using 2 programs, the latter sending text data to the first displayed using stdout?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM