C语言 if语句的介绍和使用

/*
if 语句的结构描述:
    if(表达式1){
              语句块1//表达式1是真运行此语句块
              }else if(表达式2){
              语句块2//表达式1假,表达式2真,运行此语句块
              }else if(表达式3){
              语句块3//表达式1假,表达式2假,表达式3真运行此语句块
              }else{
              语句块4//表达式1,2,3都为假运行此语句块
                    }
*/

/*
例题:
输入一个0-100的成绩,按0-59是E,60-69是D,70-79是C,80-89是B,90-100是A,分成几个分数等级。
*/

#include <stdio.h>
int main(int argc, const char * argv[]) {
    //定义一个变量
    int score = 0;
    //提示用户输入一个分数
    printf("请您输入分数:\n");
    //获取用户输入的分数
    scanf("%d",&score);
    /*
//分析:
     score>=0 && score<=59 打印 E

     score>=60 && score<=69 打印 D

     score>=70 && score<=79 打印 C

     score>=80 && score<=89 打印 B

     score>=90 && score<=100 打印 A

     score<0 || score>100 打印 您输入的成绩不合法!
     */

//代码实现
    if(score>=0 && score<=59){printf("E");}

    else if(score>=60 && score<=69){printf("D");}

    else if(score>=70 && score<=79){printf("C");}

    else if(score>=80 && score<=89){printf("B");}

    else  if(score>=90 && score<=100){printf("A");}

        else{printf("您输入的数据不合法!");}

}

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值