How to input a real number in C language and output its…
In the C language, the fabs() function can be used to calculate the absolute value of a real number.
The example code is shown below:
#include <stdio.h>
#include <math.h>
int main() {
double num;
printf("请输入一个实数:");
scanf("%lf", &num);
double absNum = fabs(num);
printf("该实数的绝对值为:%lf\n", absNum);
return 0;
}
In the above code, first a floating-point number is obtained from user input using the scanf() function, then the absolute value of the number is calculated using the fabs() function, and finally the result is printed using the printf() function.