#include <stdio.h>
int main()
{
    unsigned int score;
    printf("输入分数:\n");
    scanf_s("%d", &score);
    if (score <= 100)
    {
        switch (score / 10)
        {
        case 0:
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:printf("等级E\n"); break;
        case 6:printf("等级D\n"); break;
        case 7:printf("等级C\n"); break;
        case 8:printf("等级B\n"); break;
        case 9:
        case 10:printf("等级A\n"); break;

        }
    }
    else printf("!非法输入");//这一句是 当输入的数小于0时,就会显示
    return 0;
}

以上是switch语句

以下是if语句书写

#include <stdio.h>
int main()
{
    unsigned int score;
    printf("输入分数:\n");
    scanf_s("%d", &score);
    if (score >= 90 && score <= 100)
    {
        printf("你的等级A");
    }
    if (score >= 80 && score < 90)
    {
        printf("你的等级B");
    }
    if (score >= 70 && score < 80)
    {
        printf("你的等级C");
    }
    if (score >= 60 && score < 70)
    {
        printf("你的等级D");
    }
    if (score < 60 && score >= 0)
    {
        printf("你的等级E\n");
    }
    else printf("!非法输入");//这一句是 当输入的数小于0时,就会显示
    
    return 0;
}

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐