【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");
        
    }
}

 

posted @ 2019-11-11 12:32  木子欢儿  阅读(9748)  评论(0编辑  收藏  举报