📅  最后修改于: 2020-09-25 07:36:11             🧑  作者: Mango
它在
[Mathematics] |x| = fabs(x) [C++ Programming]
double fabs(double x);
float fabs(float x);
long double fabs(long double x);
double fabs(T x); // For integral type
fabs() 函数采用单个参数,并返回double
, float
或long double
类型的值。
fabs() 函数采用单个参数x,其返回绝对值。
fabs() 函数返回x的绝对值,即| x |。
#include
#include
using namespace std;
int main()
{
double x = -10.25, result;
result = fabs(x);
cout << "fabs(" << x << ") = |" << x << "| = " << result << endl;
return 0;
}
运行该程序时,输出为:
fabs(-10.25) = |-10.25| = 10.25
#include
#include
using namespace std;
int main()
{
long int x = -23;
double result;
result = fabs(x);
cout << "fabs(" << x << ") = |" << x << "| = " << result << endl;
return 0;
}
运行该程序时,输出为:
fabs(-23) = |-23| = 23