您的位置:首页 > 编程语言 > C语言/C++

题目:学习成绩 >= 90分的同学用A表示,60 - 89分之间的用B表示,60分以下的用C表示

2018-03-21 20:13 369 查看
题目:学习成绩 >= 90分的同学用A表示,60 - 89分之间的用B表示,60分以下的用C表示
#include<stdio.h>
int main()
{
int score = 0;
printf("please input a score\n");
scanf("%d", &score);
if (!(score >= 0 && score <= 100))
printf("输入错误\n");
while (score >= 0 && score<=100)
{

if (score >= 90)
{
printf("A\n"); break;
}
else if (score >= 60)
{
printf("B\n"); break;
}
else
{
printf("C\n");
break;
}
}

system("pause");

}
2.采用条件运算符的嵌套
#include "stdio.h"
main()
{
int score;
char grade;
printf("please input a score\n");
scanf_s("%d", &score);
grade = score >= 90 ? 'A' : (score >= 60 ? 'B' : 'C');
printf("%d belongs to %c", score, grade);
system("pause");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C语言
相关文章推荐