C language practice question 14

foreword

Why did I start playing again, and quickly sent all the drafts I had hoarded.

Question Fourteen

Question:
Use the nesting of conditional operators to complete this question: students with academic scores >=90 points are represented by A, those with scores between 60-89 are represented by B, and students with scores below 60 are represented by C.

My thoughts:
When I first read the topic, I thought it was very suitable to use the switch statement, but the topic limited the scope and there was no other way.
1. Input: grades
Output: corresponding grades

my process

#include<stdio.h>
int main()
{
    
    
    int score;
    char grade;
    printf("请输入分数: ");
    scanf("%d",&score);
    grade=(score>=90)?'A':((score>=60)?'B':'C');
    printf("%c\n",grade);
    return 0;
}

operation result:
insert image description here

Guess you like

Origin blog.csdn.net/weixin_52248428/article/details/116432348