C语言 编一程序,从键盘输入一个实数,输出其绝对值。
编一程序,从键盘输入一个实数,输出其绝对值。#include<stdio.h>main(){float fx;printf("please input a float:");scanf("%f",&fx);if(fx<0)fx=-fx;printf("|fx|=%f",fx);}.
·
编一程序,从键盘输入一个实数,输出其绝对值。
常规方法:
#include<stdio.h>
main()
{
float fx;
printf("please input a float:");
scanf("%f",&fx);
if(fx<0)
fx=-fx;
printf("|fx|=%f",fx);
}
更简单的方法:
#include <stdio.h>
int main()
{
float fx;
printf("please input a float:");
scanf("%f",&fx);
printf("|fx|=%f\n",(fx>0)?fx:-fx);
return 0;
}
更多推荐
所有评论(0)