从键盘任意输入一个实数,不使用计算绝对值函数编程计算并输出该实数的绝对值。 **输入格式要求:"%f" 提示信息:"Input a float number:" **输出格式要求:"Absolute value of x is %f\n" 程序运行示例如下: Input a float number:-2.3 Absolute value of x is 2.300000
根据绝对值的定义,正数的绝对是是其本身,复数的绝对值是其相反数,就可以实现。
具体程序如下:
void calAbs() { float num; printf("搜并碧input a float number:"); scanf_s("%f", &num); if (num <蔽拿 世举0) num = 0 - num; printf("Absolute value of x is %f
",num); }