c语言求绝对值的代码怎么写
lewis
2017-05-25
19次阅读
在C语言中,可以使用abs()函数来求一个数的绝对值。该函数的原型为:
int abs(int x);
以下是一个示例代码:
#include <stdio.h>
#include <stdlib.h>
int main() {
int x = -5;
int result = abs(x);
printf("绝对值为:%d\n", result);
return 0;
}
运行以上代码将输出:
绝对值为:5

发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。