题目
学习成绩>=90分的同学用A表示,60-89分之间的用B表示,60分以下的用C表示。
编程解析:
思路1:条件运算符:运用实例a>b?a:b
思路2:if else结构的运用
思路3:switch case结构的运用
//思路1:
#include <stdio.h>
int main(int argc, char const *argv[])
{
int score;
char grade;
printf("请您输入分数: ");
scanf("%d",&score);
grade=(score>=90)?'A':((score>=60)?'B':'C');
printf("您的等级是:%c\n",grade);
return 0;
}
思路2
#include <stdio.h>
int main(int argc, char const *argv[])
{
int score;
printf("请您输入分数: ");
scanf("%d",&score);
if(score>=90)
{
printf("A\n");
}
else if (score>=60)
{
printf("B\n");
}
else
{
printf("C\n");
}
return 0;
}
#include <stdio.h>
int main(int argc, char const *argv[])
{
int score;
printf("请您输入分数: ");
scanf("%d",&score);
int ret=score/10;
switch (ret)
{
case 10:printf("A\n");break;
case 9:printf("A\n");break;
case 8:printf("B\n");break;
case 7:printf("B\n");break;
case 6:printf("B\n");break;
case 5:printf("C\n");break;
case 4:printf("C\n");break;
case 3:printf("C\n");break;
case 2:printf("C\n");break;
case 1:printf("C\n");break;
case 0:printf("C\n");break;
default:printf("程序错误!\n");break;
}
return 0;
}
标签:练习题,case,int,经典,60,C语言,break,score,printf
From: https://blog.csdn.net/warmmaple/article/details/137054331