Home>Article>Backend Development> How to judge the level of C language input scores
Judgment method: 1. Use the "switch(score/10){case 9:A;...case 6:D;default:E;}" statement; 2. Use "if(score>= 90)A;else if(score>=80)B;...else if(score>=60)D;elseE;" statement.
The operating environment of this tutorial: windows7 system, c99 version, Dell G3 computer.
Analysis: We can either use else if to make judgments or switch case to make judgments.
The question requirements are as follows: Enter the student's score and automatically determine the grade
Grade | Grade |
---|---|
90 | A level |
80 | B level |
70 | C level |
60 | D Level |
0
|
E Level |
1. Use the switch...case statement to determine the level
#includeRunning resultsint main() { int i; scanf("%d",&i); i/=10; switch(i){ case 9: printf("A"); break; case 8: printf("B"); break; case 7: printf("C"); break; case 6: printf("D"); break; default: printf("E"); break; } return 0; }
##2. Use if..else..if statement
#includeRunning resultsint main() { 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; }
Related recommendations: "
C Language Video TutorialThe above is the detailed content of How to judge the level of C language input scores. For more information, please follow other related articles on the PHP Chinese website!