首页 C语言学习


输入成绩,判断成绩,输出等级


用switch选择语句编程

#include<stdio.h>
int main()
{
int score,x;
scanf("%d",&score);
if ((score >100)||(score < 0)) printf("Your score is invalid!");
else{ x=score/10;
switch(x){
case 10:
case 9:
printf("Your grade is A!\n");
break;
case 8:
printf("Your grade is B!\n");
break;
case 7:
printf("Your grade is C!\n");
break;
case 6:
printf("Your grade is D!\n");
break;
default:
printf("Your grade is E!\n");
break;
}
}
return 0; 
}


用if-else选择语句

#include <stdio.h>
int main(void) { 
int score;
scanf("%d",&score);
if(score>100||score<0)
printf("Your score is invalid!");
else
if(score>=90)
printf("Your grade is A!");
else
if(score>=80)
printf("Your grade is B!");
else
if(score>=70)
printf("Your score is C!");
else
if(score>=60)
printf("Your score is D!");
else
printf("Your grade is E!");
return 0;
}





文章评论

目录