[求助]一个关于数据类型的问题
这个程序如何改才可以使输入小数点后面的数字有效 # include"stdio.h"
main()
{
int x,y;
printf("\nplease input x:");
scanf("%d",&x);
if(x<1)
y=x;
else if(x>=1&&x<10)
y=2*x-1;
else if(x>=10)
y=3*x-11;
printf("%d",y);
getch();
}
----------------解决方案--------------------------------------------------------
把%d改成%f
# include"stdio.h"
main()
{
float x,y;
printf("\nplease input x:");
scanf("%f",&x);
if(x<1)
y=x;
else if(x>=1&&x<10)
y=2*x-1;
else if(x>=10)
y=3*x-11;
printf("%f",y);
getch();
}
----------------解决方案--------------------------------------------------------