Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - What function can be used to find the absolute value of two integers?
What function can be used to find the absolute value of two integers?
To find the absolute value of the difference between two integers, you can use the absolute value ABS function of C language, the header file is stdlib.h, and the format of ABS function is ABS (

For example:

# include & ltstdlib.h & gt

# include & ltstdio.h & gt

int main(void)

{

int a =- 100;

int b = 200

Printf ("absolute value: %d\n",? ABS(a-b));

Returns 0;

}

The result is "absolute value:? 300"。

Extended data:

The number parameter of ABS function cannot be arbitrary, floating-point number or double-precision numerical expression. If number contains Null, it will return null. If it is an uninitialized variable, it returns 0. If the number parameter is not a number, but some characters, Null is returned.

C language has fabs function, and also seeks absolute value. The difference is that the parameters and return values of fabs function are real types. On a 32-bit computer, if you don't use system functions and conditional statements, you can use fabs function to get the absolute value.