//利用条件运算符的嵌套来完成此题,学习成绩>=90分的同学用A来表示,60-89分之间的用B 表示,60分以下用C表示。
#include <stdio.h>
main()
{
int score;
char grade;
printf("please input a score\n")
scanf("%d",&score);
grade=score>=90?'A':(score>=60?'B':'C');//条件运算符,(a>b)?a:b
printf("%d belongs to %c",score,grade);
return 0;
}
#include <stdio.h>
main()
{
int score;
char grade;
printf("please input a score\n")
scanf("%d",&score);
grade=score>=90?'A':(score>=60?'B':'C');//条件运算符,(a>b)?a:b
printf("%d belongs to %c",score,grade);
return 0;
}
本文介绍了一个简单的C语言程序,该程序使用条件运算符嵌套来根据输入的成绩将学生的学习成绩分为三个等级:90分及以上为A级,60到89分为B级,60分以下为C级。

被折叠的 条评论
为什么被折叠?



