Home » C++ Math abs() Functions

C++ Math abs() Functions

by Online Tutorials Library

C++ Math abs()

The function finds the absolute value of a given number.

Suppose a number is ‘x’:

Difference between abs() and fabs()

The abs() function does not support float or double type arguments while fabs() function supports float, double as well as integer type arguments.

Syntax

Parameter

x: The value whose absolute value is to be determined.

Return value

It returns the absolute value of x.

Example 1

Let’s see the simple example when the value of x is negative.

Output:

Value of x is :-9  Absolute value of x is : 9     

In this example, abs() function computes the absolute value of x and returns the value 9.

Example 2

Let’s see the simple example when the value of x is positive.

Output:

Value of x is :89  Absolute value of x is : 89     

In this example, abs() function computes the absolute value of x.

Next TopicC++ Math Functions

You may also like