用C语言中的if else if等实现,从屏幕上输入一个学生的成绩(0-100),对学生成绩进行评定

/*
 * 1、从屏幕上输入一个学生的成绩(0-100),对学生成绩进行评定:
 *      <60为"E"
 *      60~69为"D"
 *      70~79为"C"
 *      80~89为"B"
 *      90以上为"A"
 *      <0或>100提示成绩输入错误
 * 使用:if else if等实现
 */
void hw_one() {
    char ch = '!';
    int score = 0;
    printf("请输入学生分数:");
    scanf("%d", &score);
    if (score < 0 || score > 100) {
        printf("您输入的分数有错误!\n");
    } else if (score < 60) {
        ch = 'E';
    } else if (score < 70) {
        ch = 'D';
    } else if (score < 80) {
        ch = 'C';
    } else if (score < 90) {
        ch = 'B';
    } else {
        ch = 'A';
    }
    printf("学生成绩评定为:%c", ch);
}

int main() {
    hw_one();
}

你可能感兴趣的:(试题练习,c语言,算法)