方法一:if-else
#include<stdio.h> int main() { printf("请输入成绩: "); float score; scanf_s("%f", &score); if (score >= 90) printf("成绩等级为:A "); else if (score >= 80) printf("成绩等级为:B "); else if (score >= 70) printf("成绩等级为:C "); else if (score >= 60) printf("成绩等级为:D "); else printf("成绩等级为:E "); }
方法2:switch语句
#include<stdio.h> int main() { printf("请输入成绩: "); float score; scanf_s("%f", &score); switch ((int)score/10) { case 10: case 9:printf("成绩等级为:A "); break; case 8:printf("成绩等级为:B "); break; case 7:printf("成绩等级为:C "); break; case 6:printf("成绩等级为:D "); break; default:printf("成绩等级为:E "); } }