#include <iostream>
#include <cmath> /* fabs */
using namespace std;
int main ()
{
cout<<"The absolute value of 3.1416 is "<< fabs (3.1416) <<endl;
cout<< "The absolute value of -10.6 is "<< fabs (-10.6) <<endl;
/*
The absolute value of 3.1416 is 3.1416
The absolute value of -10.6 is 10.6
*/
return 0;
}
[Mathematics] |x| = fabs(x) [In C programming]
#include<iostream>
#include<cmath>
using namespace std;
int main(){
//fabs() is the short form of float absolute.
//By this function you can change a negative floating point number
//to positive.
float num = -10.6;
cout<<fabs(num)<<endl;
return 0;
}