3269 - 习题4-8-2 百分制成绩转换为等级
从键盘输入一百分制成绩,要求输出其所对应的等级'A', 'B', 'C', 'D'。85分以上(含)为'A',70~84分之间为'B',60~69分之间为'C',60分以下为'D'。
请用switch语句实现。
Input
一百分制成绩
Output
百分制成绩所对应的等级,末尾换行。
Examples
Input
73
Output
B
Solution C
#include<stdio.h> int main () { int a,b; scanf("%d",&a); b=a/10; switch(b) { case 10: case 9: printf("A");break; case 8: case 7: printf("B");break; case 6: printf("C");break; default:printf("D"); } return 0; }
Solution C++
#include<iostream> using namespace std; int main() { int score; cin>>score; int t=score/5; char c; switch (t) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: c='D'; break; case 12: case 13: c='C'; break; case 14: case 15: case 16: c='B'; break; case 17: case 18: case 19: case 20: c='A'; break; } cout<<c<<endl; return 0; }