河北单招专科学校排名:能帮我检查一下错在哪里吗

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 15:26:53
输入x,求y的值
┌ 2.4 + sinx 当 x < 2 时
y=│ 0 当 x = 2 时
└ │2.45 - x│ 当 x > 2 时

#include<math.h>
#include<stdio.h>
main()
{
int x;
float y;
scanf("%d",&x);
if(x<2) y=2.4+sin(x*3.14/180);
else if(x==2) y=0;
else y=fabs(2.45-x);
printf("%d",y);
}
该题错在哪里呢?

输出格式错了,应是
printf("%f",y);

---------------------
锦上添花:
x最好用float, 不用 int.
float x;
scanf("%f",&x);
题意x好像是弧度,不是角度
y= 2.4 + sin(x)中 不用 *3.14/180 化弧度.