c语言求绝对值的代码如何写
在C语言中,可使用abs()函数来求一个数的绝对值。该函数的原型为:
int abs(int x);
以下是一个示例代码:
#include <stdio.h>
#include <stdlib.h>
int main() {
int x = ⑸;
int result = abs(x);
printf("绝对值为:%d
", result);
return 0;
}
运行以上代码将输出:
绝对值为:5
TOP