C++ absolute value
The
abs()
function in C++ returns the absolute value of the argument.
#include <iostream> #include <cmath> using namespace std; int main() { cout << abs(-4.4); return 0; }
4.4
c++ abs
Syntax of abs()
The syntax of the abs() function is:
abs(double num);
abs() Parameters
The
abs()
function takes the num parameter.
- A floating point number - num can be double, float, long double
absolute value c++
abs() Return
std abs
- The absolute value of
num
.
cmath absolute value
#include <iostream> #include <cmath> using namespace std; int main() { double num = -44.55, res; res = abs(num); cout << "abs(" << num << ") = " << res; return 0; }
abs(-44.55) = 44.55
c++ math abs
#include <iostream> #include <cmath> using namespace std; int main() { int num = -44; double res; res = abs(num); cout << "abs(" << num << ") = " << res; return 0; }
abs(-44) = 44