abs C · 数学函数
求整数的绝对值。
怎么用
int r = abs(整数);
小例子
#include <stdio.h>
#include <stdlib.h>
int main(void) {
printf("%d", abs(-5));
return 0;
}
运行结果
输出 5
提醒:整数用 abs,浮点数用 fabs;INT_MIN 的绝对值可能溢出
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← C全部词条abs C · 数学函数求整数的绝对值。
int r = abs(整数);
#include <stdio.h>
#include <stdlib.h>
int main(void) {
printf("%d", abs(-5));
return 0;
}
输出 5
提醒:整数用 abs,浮点数用 fabs;INT_MIN 的绝对值可能溢出
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← C全部词条