霸气孤独狼图片大全:c-free 题目 为什么这个不能运行

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 14:06:31
#include "math.h"
#include "stdio.h"
void main()
{ float x,y;
printf("输入x:");
scanf("%f",&x);
if(x>=100||x<36) printf("y无定义!\n");
else
{ switch(sqrt(x))
{case 9: y=x+2;break:
case 8: y=2*x+3;break;
case 7:y=3*x+4;break;
case 6: y=4*x+3;
}
printf("结果y=%.2\n",y);
}
}
可以运行了
但是结果不对啊

(1)将#include "math.h"
#include "stdio.h"
中双引号改成<>

(2) sqrt(x)这个的返回结果是一个浮点数,而switch却一个是一个整型,因此建议改成switch((int)sqrt(x))

(3)case 9: y=x+2;break:
将冒号改成分号