edit_note帖子
214
stars积分
13,626
event加入
2011-12-10
电脑网络
经典C语言程序设计100例【程序15】
schedule发表于 2013-11-20 12:16:00
visibility查看 360
chat_bubble回复 0
#1 楼主
题目:利用条件运算符的嵌套来完成此题:学习成绩>=90分的同学用A表示,60-89分之间的用B表示,
60分以下的用C表示。
1.程序分析:(a>b)?a:b这是条件运算符的基本例子。
2.程序源代码:
main()
{
int score;
char grade;
printf(“please input a score\n“);
scanf(“%d“,&score);
grade=score>=90?‘A‘:(score>=60?‘B‘:‘C‘);
printf(“%d belongs to %c“,score,grade);
}
60分以下的用C表示。
1.程序分析:(a>b)?a:b这是条件运算符的基本例子。
2.程序源代码:
main()
{
int score;
char grade;
printf(“please input a score\n“);
scanf(“%d“,&score);
grade=score>=90?‘A‘:(score>=60?‘B‘:‘C‘);
printf(“%d belongs to %c“,score,grade);
}
forum
暂无回复,快来抢沙发!
登录 后才能回复
flag举报帖子