fabs()函数返回参数的绝对值。
数学上| a |。如果a是参数中给出的值。
句法:
double fabs(double a);
float fabs(float a);
int fabs(int a);
Parameter:
Return:
Error:
no matching function for call to ‘fabs()’ like this.
#代码1
// CPP code to illustrate
// fabs() function
#include
#include
using namespace std;
int main()
{
int a = -10, answer;
answer = fabs(a);
cout << "fabs of " << a
<< " is " << answer << endl;
return 0;
}
输出 :
fabs of -10 is 10
#代码2
// CPP code to illustrate
// fabs() function
#include
#include
using namespace std;
int main()
{
long int a = -35;
double answer;
answer = fabs(a);
cout << "fabs of " << a << " is "
<< answer << endl;
return 0;
}
输出 :
fabs of -35 is 35
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。