C++ 中的 fabs()
C 或 C++ 庫函式 double fabs(double x) 返回 x 的絕對值。x − 這是浮點值。此函式返回 x 的絕對值。以下是 fabs() 函式的宣告。
double fabs(double x)
下面的示例顯示了 fabs() 函式的用法。
示例
#include <iostream>
#include <cmath>
using namespace std;
int main () {
int a, b;
a = 1234;
b = -344;
cout << "The absolute value of " << a << " is " << fabs(a) <<
endl;
cout << "The absolute value of " << b << " is " << fabs(b) <<
endl;
return(0);
}輸出
The absolute value of 1234 is 1234 The absolute value of -344 is 344
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP