黑马程序员技术交流社区
标题:
C语言 if 和switch练习
[打印本页]
作者:
jinlong129
时间:
2015-8-7 20:18
标题:
C语言 if 和switch练习
本帖最后由 jinlong129 于 2015-8-8 15:35 编辑
/*
输入一个整数score代表分数,根据分数输出等级(A-E)(用两种方式或以上)
A:90~100
B:80~89
C:70~79
D:60~69
E:0~59
*/
#include <stdio.h>
int main()
{
//1.提示用户输入分数
printf("请输入一个分数(0-100之间):\n");
//2.接收用户输入的分数
int score;
scanf("%d", &score);
if (score < 0 || score > 100) {
printf("输入不合法!!! 请重新运行\n");
return 0;
}
//3.判断等级并输出对应的等级
// 1.个人感觉性能最好
/*
int tmpe = score / 10;
if (tmpe = 9 || tmpe = 10) {
printf("你的等级是A\n"); // 90~100
} else if (tmpe = 8) {
printf("你的等级是B\n"); // 80~89
} else if (tmpe = 7) {
printf("你的等级是C\n"); // 70~79
} else if (tmpe = 6) {
printf("你的等级是D\n"); // 60~69
} else {
printf("你的等级是E\n"); // 0~69
}
*/
switch (score / 10) {
case 10:
case 9:
printf("你的等级是A\n");
break;
case 8:
printf("你的等级是B\n");
break;
case 7:
printf("你的等级是C\n");
break;
case 6:
printf("你的等级是D\n");
break;
default:
printf("你的等级是E\n");
break;
}
/*
//2.性能中等
if (score >= 90 && score <= 100) {
printf("你的等级是A\n"); // 90~100
} else if (score >= 80) {
printf("你的等级是B\n"); // 80~89
} else if (score >= 70) {
printf("你的等级是C\n"); // 70~79
} else if (score >= 60) {
printf("你的等级是D\n"); // 60~69
} else {
printf("你的等级是E\n"); // 0~69
}
*/
/*
3.性能中等
if (score >= 90 && score <= 100) {
printf("你的等级是A\n"); // 90~100
} else if (score >= 80 && score <= 89) {
printf("你的等级是B\n"); // 80~89
} else if (score >= 70 && score <= 79) {
printf("你的等级是C\n"); // 70~79
} else if (score >= 60 && score <= 69) {
printf("你的等级是D\n"); // 60~69
} else {
printf("你的等级是E\n"); // 0~69
}
*/
/*
//4.性能最差
if (score >= 90 && score <= 100) {
printf("你的等级是A\n"); // 90~100
}
if (score >= 80 && score <= 89) {
printf("你的等级是B\n"); // 80~89
}
if (score >= 70 && score <= 79) {
printf("你的等级是C\n"); // 70~79
}
if (score >= 60 && score <= 69) {
printf("你的等级是D\n"); // 60~69
}
if (score >= 0 && score <= 59) {
printf("你的等级是E\n"); // 0~69
}
*/
return 0;
}
复制代码
作者:
Mal
时间:
2015-8-7 21:15
嘿嘿
顶顶
作者:
墨琰
时间:
2015-8-7 22:10
顶你 楼主加油
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2