abs全稱是 a function returns the absolute value of its parameter.
這是一個函數,返回它的參數(整型)的絕對值。
abs 是 absolute value (絕對值)縮寫。c++ 中的一個數學函數,計算整型量的絕對值。要頭文件 #include <cmath> 或 #include <math.h>
算例:
int x=16, y= -6;
cout << abs(x) << endl;
cout << abs(y) << endl;
輸出:
16
6
浮點數的絕對值用 fabs 函數。