打印成绩
1 #include <stdio.h> 2 3 int main() 4 { 5 int grade; 6 while(scanf("%d",&grade) != EOF) 7 { 8 switch(grade /10) 9 { 10 case 9: 11 case 10: 12 printf("%c ",'A');break; 13 case 8: 14 printf("%c ",'B');break; 15 case 7: 16 printf("%c ",'C');break; 17 case 6: 18 printf("%c ",'D');break; 19 case 5: 20 case 4: 21 case 3: 22 case 2: 23 case 1: 24 case 0: 25 printf("%c ",'E');break; 26 default: 27 printf("Score is error! "); 28 } 29 } 30 return 0; 31 }
参考c++
#include <math.h> #include <stdio.h> int main(void) { int r; while (scanf("%d", &r) != EOF) { if (r < 0) puts("Score is error!"); else if (r < 60) puts("E"); else if (r < 70) puts("D"); else if (r < 80) puts("C"); else if (r < 90) puts("B"); else if (r < 101) puts("A"); else puts("Score is error!"); } return 0; }