Home>Article>Backend Development> How to calculate the absolute value in C language
How to implement absolute value in C language: 1. If it is an integer number, you can use the abs function to get its absolute value; 2. If it is a floating-point number, you can use the fabs function to get its absolute value.
The operating environment of this article: Windows 7 system, Dev-C version 5.11, Dell G3 computer.
How to implement absolute value in C language:
1. In C language, you can use the abs or fabs function to get the absolute value of a number, which is contained in math.h header file, so add the header file to the code first, as shown in the figure below.
#2. If it is an integer number, you can use the abs function to get its absolute value. The code is as shown in the figure below.
#3. If it is a floating-point number, you can use the fabs function to get its absolute value. The code is as shown in the figure below.
#4. Finally, you can use the Printf function to print out the numbers converted into absolute values and view the code running results, as shown in the figure below.
#5. After debugging and running the code, you can see the result after converting the number into an absolute value, as shown in the figure below.
The above is the detailed content of How to calculate the absolute value in C language. For more information, please follow other related articles on the PHP Chinese website!