web123456

Python editing program, enter a percentage score based on the input percentage number_input a percentage score, use the switch statement to write the program, and require the output score level A B C D D, E. Above 90 is A...

Enter a percentage score, use the switch statement to write a program, and require the output score grade A B C D, E. Above 90

Program: int main()

{int n;

scanf("%d",&n);

switch(n/10)

{case 10:case 9: printf("A\n"); break;

case 8: printf("B\n"); break;

case 7: printf("C\n"); break;

case 6: printf("D\n"); break;

default:printf("E\n");

}

return 0;

}

1. Switch is reserved in some computer languages, and its function is mostly to make judgments and choices. In C language, switch (switch statement) is often used with case break default. Principle: (n) after switch can be an expression or (and usually) a variable. The values ​​in the expression will then be compared with the numbers in the case, and if they match a case, the subsequent code will be executed. The purpose of break is to prevent the code from being automatically executed to the next line.

2. The switch statement is similar to a series of IF statements with the same expression. In many cases, the same variable (or expression) needs to be compared with many different values ​​and execute different codes based on which value it equals. This is exactly what the switch statement is for. Note: Note that unlike other languages, the role of the continue statement on the switch is similar to that of break. If there is a switch in the loop and you want to continue to the next cycle in the outer loop, use continue 2.

matlabEnter a percentage score and require output score grades, A, B, C, D, E

Score = [76, 80, 90, 91, 55, 66, 100, 98, 88];

L = length(Score);

for (i=1 : L)

k = floor(Score(i)/10);

switch k

case {9, 10}

disp('A')

case 8

disp('B')

case 7

disp('C')

case 6

disp('D')

otherwise

disp('E')

end

end

Write a program: Enter a percentage from the keyboard to form the score. It is required to output the score in the form of "excellent", "good", "medium", and "poor"

BufferedReader buf = new BufferedReader(new InputStreamReader(); Stringstr = (); int g = (str);if(g >= 90){ ("Outstanding");else if(75<=g && g<=89) ("Good");else if(60<=g && g<=74) ("Medium");else if(g<60 ) ("Poor");

C++ program gives a score of 100 and requires the output scores of 'A', 'B', 'C', 'D', 'E'. A score of 90 or above is ‘A’

There are several questions,

The semicolon after x is a Chinese character

mainfunctionIt's void, don't need to return 0;

In addition, according to the question, there should be an equal sign when 90, 80, etc. #includeusing namespace std;void main(){cout<>x; if (x<0||x>100) cout<=90) cout<=80) cout<=70) cout<=60) cout<

beg! Programming with VFP. Given a percentage score, requiring the output scores of A, B, C, D, and E. Use if statement.

clear

input "Enter the test score" to chj

if chj<60

dj="E"

else

if chj<70

dj="D"

else

if chj<80

dj="C"

else

if chj<90

dj="B"

else

dj="A"

endif

endif

endif

endif

? dj

Write a program and require input percentage scores. According to this score, output levels: 90-100 is a, 80-89 is b, 70-79 is c, 60-69 is d, and below 60 is e.

switch (floor(x/10)){ case 10: case 9: printf("a"); break; case 8: printf("b"); break; case 7: printf("c"); break; case 6: printf("d"); break; default: printf("e");}

Use the scanf function to enter a percentage score (integer quantity), and require the output score levels A, B, C, D, E.

Use switch:

#include

int main()

{ float score;

char grade;

printf("please input a score:");

scanf("%f",&score);

while (score>100||score<0)

{printf("\nsorry your input is wrong");

scanf("%f",&score);

} ;

switch((int)(score/10))

{case 10:

case 9: grade='A';break;

case 8: grade='B';break;

case 7: grade='C';break;

case 6: grade='D';break;

case 5:

case 4:

case 3:

case 2:

case 1:

case 0: grade='E';

}

printf("the score is%5.1f,the grade is%c\n ",score,grade);

system("pause");

}

Using if:

#include

main()

{ int c,i,j;

printf("\nInput a score:");

scanf("%d",&c);

if(c>100||c<0)

printf("sorry,your input is wrong!\n");

else

{ printf("\nThe score is %d",c);

if(c>=90&&c<=100)

{printf("\nHe got an A");}

else if(c>=80&&c<90)

{printf("\nHe got an B");}

else if(c>=70&&c<80)

{printf("\nHe got an C");}

else if(c>=60&&c<70)

{printf("\nHe got an D");}

else if(c>=0&&c<60)

{printf("\nHe got an E");} } }

Click to view hidden content