=90)A;else if( Score>=80)B;..else if (score>=60)D;elseE;" statement."/> =90)A;else if( Score>=80)B;..else if (score>=60)D;elseE;" statement.">

Home>Article>Backend Development> How to judge the level of C language input scores

How to judge the level of C language input scores

青灯夜游
青灯夜游 Original
2021-04-27 11:32:50 26787browse

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.

How to judge the level of C language input scores

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
##The level is automatically determined after entering the score in C language Two ways to implement the function

  • Use the switch...case statement to determine the level

  • Use the else if statement

1. Use the switch...case statement to determine the level

#include  int 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; }

Running results

How to judge the level of C language input scores

##2. Use if..else..if statement

#include  int 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; }
Running results

How to judge the level of C language input scoresRelated recommendations: "

C Language Video Tutorial

"

The 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn