fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int score;
  5. printf("请输入分数:");
  6. scanf("%d", &score);
  7.  
  8. if (score < 0 || score > 100) {
  9. printf("error!\n");
  10. return 0;
  11. }
  12.  
  13. // 用整数除法把分数分段,简化switch分支
  14. switch(score / 10) {
  15. case 10:
  16. case 9:
  17. case 8:
  18. // 85~100:8/9/10分位,且8开头要≥85
  19. if (score >= 85) printf("A\n");
  20. else printf("B\n");
  21. break;
  22. case 7: printf("B\n"); break;
  23. case 6: printf("C\n"); break;
  24. default: printf("D\n"); // 0~59
  25. }
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 5316KB
stdin
69
stdout
请输入分数:C