How to judge the level of C language input scores

青灯夜游
Release: 2023-01-05 16:11:50
Original
26906 people have browsed it

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
0E 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 <stdio.h>
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; 
}
Copy after login

Running results

How to judge the level of C language input scores

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

#include <stdio.h>
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; 
}
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!