C Exercise Example 15
100 cases of classic C language
Title: Using nested conditional operator to complete this question: academic> = 90 points the students represented by A, between 60-89 points represented by B, 60 points or less is represented by C.
Program analysis: (a> b) a: ? B This is a basic example of a conditional operator.
Source Code:
// Created by www.w3big.com on 15/11/9. // Copyright © 2015年 本教程. All rights reserved. // #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; }
The above example output is:
请输入分数: 87 B