本文共 1523 字,大约阅读时间需要 5 分钟。
c++ cstdlib
abs() function is a library function of cstdlib header. It is used to get the absolute value. It accepts a value (int, long int, long long it) and returns its absolute value. This method is an overloaded method of (that is used for getting absolute value of the floating-point values).
abs()函数是cstdlib标头的库函数。 用于获取绝对值。 它接受一个值(int,long int,long long it)并返回其绝对值。 此方法是的的重载方法用于获取浮点值的绝对值)。
Syntax of abs() function:
abs()函数的语法:
C++11:
C ++ 11:
int abs (int n); long int abs (long int n); long long int abs (long long int n);
Parameter(s):
参数:
n – represents an Integral value whose absolute value to found.
n –表示要找到其绝对值的整数值。
Return value:
返回值:
It returns the absolute value of n.
它返回n的绝对值。
Example:
例:
Input: n = -10 Function call: abs(n); Output: 10 Input: n = 10 Function call: abs(n); Output: 10
// C++ code to demonstrate the example of// abs() function#include#include using namespace std;// main() sectionint main(){ int n; n = -10; cout << "abs(" << n << "): " << abs(n) << endl; n = 10; cout << "abs(" << n << "): " << abs(n) << endl; n = -12345678; cout << "abs(" << n << "): " << abs(n) << endl; n = 12345678; cout << "abs(" << n << "): " << abs(n) << endl; return 0;}
Output
输出量
abs(-10): 10abs(10): 10 abs(-12345678): 12345678abs(12345678): 12345678
Reference:
参考:
翻译自:
c++ cstdlib
转载地址:http://ewozd.baihongyu.com/