在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
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:c语言输出绝对值代码怎么写