Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to find the absolute value in C language?
How to find the absolute value in C language?
//Find the absolute value

# include & ltiostream & gt

# include & ltiomanip & gt

# include & ltcmath & gt

# Define PI 3. 14 15927

Use namespace std

int main()

{//C++ Find the absolute value: abs () for plastic and fabs () for floating point.

Double r;

And (CIN >; & gtr){

cout & lt& ltsetprecision(2)& ltSTD::fixed & lt; & ltfabs(r)& lt; & ltendl

}

Returns 0;

}

Extended data:

Absolute value function in c language

Different types of data use different types of absolute value functions:

1, integer:

int abs(int i)? //Returns the absolute value of the integer parameter I 12.

2. plural:

Double cab (complicated structure znum)? //Returns the absolute value of the complex number znum? 1

3, double precision floating-point type:

Double fab (double x)? //Returns the absolute value of the double-precision parameter X 1

4. Long integer:

Dragon labs (dragon n)? //Returns the absolute value of long integer parameter n.