在C语言中,可以使用abs()
函数来计算一个数的绝对值。该函数位于stdlib.h
头文件中。
示例代码:
#include <stdio.h>
#include <stdlib.h>
int main() {
int num = -10;
int abs_num = abs(num);
printf("The absolute value of %d is %d\n", num, abs_num);
return 0;
}
输出结果:
The absolute value of -10 is 10
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: c语言怎么编写一个简单的单链表