解题思路: 1. 先看题目,找出适合的方法,比如这的题目就和条件有关(分数和评级有关),因此可以使用if条件语句,if else嵌套,Switch语句来做此题.
2. 先声明一个int类型的变量,来获取计算机给这个变量分配内存.
3. 利用scanf()获取用户的输入.
4. 利用自己所选语句来进行判定并输出.
注意事项: 因为题目要求是输入0到100,故我们不需要用代码说明用户输入为负值、大于100、带小数的情况。
if 条件语句后面,注意别加分号
参考代码:
i:只利用if语句
#include <stdio.h> int main(void) { int score; scanf("%d", &score); if (score >= 90) printf("A"); if (score >= 80 && score < 90) printf("B"); if (score >= 70 && score < 80) printf("C"); if (score >= 60 && score < 70) printf("D"); if (score < 60) printf("E"); return 0; }
ii:if else嵌套
#include <stdio.h> int main(void) { int score; scanf("%d", &score); if (score >= 90) printf("A"); else if (score >= 80) printf("B"); else if (score >= 70) printf("C"); else if (score >= 60) printf("D"); else printf("E"); return 0; }
3.switch语句
#include<stdio.h> int main(){ int score; scanf("%d",&score); switch(score/10){ // a/10是取整,说明要执行的语句 case 10: // 执行完这条语句,没有break,因此会继续向下执行语句9 case 9: putchar('A'); break; case 8: putchar('B'); break; case 7: putchar('C'); break; case 6: putchar('D'); break; default: putchar('E'); } return 0; }
0.0分
0 人评分
C语言训练-求1+2!+3!+...+N!的和 (C语言代码)浏览:542 |
简单的a+b (C语言代码)浏览:676 |
C语言训练-计算:t=1-1/(2*2)-1/(3*3)-...-1/(m*m) (C语言代码)浏览:784 |
剪刀石头布 (C语言代码)不知道怎么直接在scanf中用枚举变量浏览:1316 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:483 |
WU-输出九九乘法表 (C++代码)浏览:1671 |
WU-整数平均值 (C++代码)浏览:1244 |
校门外的树 (C语言代码)浏览:702 |
用筛法求之N内的素数。 (C语言代码)浏览:669 |
Tom数 (C语言代码)浏览:495 |