C++ 中的llabs() 函數返回 long long int 數據的絕對值。
llabs() 函數可以被認為是 abs() 的 long long int
版本。
它在<cstdlib> 頭文件中定義。
[Mathematics] |x| = llabs(x) [C++ Programming]
llabs() 原型 [從 C++ 11 標準開始]
long long llabs(long long x); long long int llabs(long long int x);
llabs() 函數采用 long long
或 long long int
類型的單個參數並返回相同類型的值。
參數:
x
:返回絕對值的 long long 或 long long int 數據。
返回:
llabs() 函數返回 x 的絕對值,即 |x|。
示例:llabs() 函數如何在 C++ 中工作?
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
long long x,y;
x = -79182028361LL;
y = 129301730192LL;
cout << "llabs(" << x << ") = |" << x << "| = " << llabs(x) << endl;
cout << "llabs(" << y << ") = |" << y << "| = " << llabs(y) << endl;
return 0;
}
運行程序時,輸出將是:
llabs(-79182028361) = |-79182028361| = 79182028361 llabs(129301730192) = |129301730192| = 129301730192
相關用法
- C++ llround()用法及代碼示例
- C++ lldiv()用法及代碼示例
- C++ llrint()用法及代碼示例
- C++ list assign()用法及代碼示例
- C++ log2()用法及代碼示例
- C++ list front()用法及代碼示例
- C++ list::remove()、list::remove_if()用法及代碼示例
- C++ lrint() and llrint()用法及代碼示例
- C++ list back()用法及代碼示例
- C++ list merge()用法及代碼示例
- C++ ldiv()用法及代碼示例
- C++ list remove()用法及代碼示例
- C++ list push_back()用法及代碼示例
- C++ list::begin()、list::end()用法及代碼示例
- C++ list::operator=用法及代碼示例
- C++ list erase()用法及代碼示例
- C++ list::empty()、list::size()用法及代碼示例
- C++ list resize()用法及代碼示例
- C++ list pop_front()用法及代碼示例
- C++ list empty()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ llabs()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。