C语言编程问题

给出一百分制成绩,要求输出成绩等级‘A’、‘B’、‘C’、‘D’、‘E’。90分以上为‘A’,80~89分为‘B’,70~79分为‘C’,60~69分为‘D’,60分以下为‘E’,
运行结果:
input student score:90.5↙
score: 90.5,grade:A
就是那个输出score:90.5,怎么写,其他都会

/*

89

score: 89, grade: B

90.5

score: 90.5, grade: A

40

score: 40, grade: E

101

无效分数。

-20

无效分数。

79

score: 79, grade: C

q

Press any key to continue

*/

#include <stdio.h>

int main() {
double score;
while(scanf("%lf",&score) == 1) {
if(score < 0 || score > 100) printf("无效分数。\n");
else if(score >= 90) printf("score:% g, grade: A\n",score);
else if(score >= 80) printf("score:% g, grade: B\n",score);
else if(score >= 70) printf("score:% g, grade: C\n",score);
else if(score >= 60) printf("score:% g, grade: D\n",score);
else printf("score:% g, grade: E\n",score);
}
return 0;
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-04-04
可以写printf("score: %.1f, grade: %c\n",x,c);
稳妥一定可以写printf("score: %.1f, grade: %c\n",x+0.05,c);
第2个回答  2014-04-04
让我来做的话我会以字符串接受输入,然后在score:后面原样打印这个字符串。至于等级那可以把字符串转换成浮点数再判断。
第3个回答  2014-04-04
定义浮点数:float a=0;
输入浮点数:scanf("%f",&a);
输出浮点数:printf("%f",a);
定义输出格式:printf("%9.2f ",a);//表示输出场宽为9的浮点数, 其中小数位为2, 整数位为6,小数点占一位, 不够9位右对齐。
第4个回答  2014-04-04
printf("score:%.1f",score);//score要是float型
第5个回答  2014-04-04
用浮点数的数据类型就可以 输出的时候要求一位小数点
相似回答