算法1:

#include <stdio.h>

int main() {
    float score;
    printf("请输入百分制成绩:");
    scanf("%f", &score);
    if (score < 60) {
        printf("不合格\n");
    } else if (score < 70) {
        printf("合格\n");
    } else if (score < 80) {
        printf("中等\n");
    } else if (score < 90) {
        printf("良好\n");
    } else {
        printf("优秀\n");
    }
    return 0;
}

算法2:

#include <stdio.h>

int main() {
    float score;
    printf("请输入百分制成绩:");
    scanf("%f", &score);
    int level = score / 10;
    switch (level) {
        case 10:
        case 9:
            printf("优秀\n");
            break;
        case 8:
            printf("良好\n");
            break;
        case 7:
            printf("中等\n");
            break;
        case 6:
            printf("合格\n");
            break;
        default:
            printf("不合格\n");
            break;
    }
    return 0;
}
将某课程考试的百分制成绩转化为等级制成绩。转换规则为 60分以下为不合格60~69分为 合格70~79分为 中等80~89分为良好90分以上为优秀一个多分支选择问题要求分别用两种算法解决。算法1使用嵌套的if语句结构。算法2使用switch语句结构。使用c语言代码写出

原文地址: https://www.cveoy.top/t/topic/boeT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录