解题思路:利用if语句的否定特性:绕过不判断是否等于零
注意事项:double对应输入为%lf,不是%f
参考代码:#include<stdio.h>
int sign(double x)
{
if(x>0)
return 1;
else if(x<0)
return -1;
else
return 0;
}
int main()
{
double x;
int s;
scanf("%lf",&x);
s=sign(x);
printf("%d",s);
return 0;
}
0.0分
0 人评分