【C语言】判断学生成绩等级
方法一:if-else
#include<stdio.h> int main() { printf("请输入成绩:\n"); float score; scanf_s("%f", &score); if (score >= 90) printf("成绩等级为:A\n"); else if (score >= 80) printf("成绩等级为:B\n"); else if (score >= 70) printf("成绩等级为:C\n"); else if (score >= 60) printf("成绩等级为:D\n"); else printf("成绩等级为:E\n"); }
方法2:switch语句
#include<stdio.h> int main() { printf("请输入成绩:\n"); float score; scanf_s("%f", &score); switch ((int)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"); } }
本文来自博客园,作者:木子欢儿,转载请注明原文链接:https://www.cnblogs.com/HGNET/p/11834109.html