进度日志8 (if语句题目)

题目1:

写一个程序完成下列功能

1、输入一个分数score

2、score<60         输出E

3、60<=score<70 输出D

4、70<=score<80 输出C

5、80<=score<90 输出B

6、90<=score       输出A       

编程:

 #pragma warning(disable:4996)
#include <stdio.h>
void main()
{
    int score;
    printf("input a score\n");
    scanf("%d", &score);
    if (score < 60)
    {
        printf("E");
    }
    else if (score >= 60 && score < 70)
    {
        printf("D");
    }
    else if (score >= 70 && score < 80)
    {
        printf("C");
    }
    else if (score >= 80 && score < 90)
    {
        printf("B");
    }
    else if (score >= 90 )
    {
        printf("A");
    }
}

题目2:

输入三个数a,b,c,按由小到大的顺序输出

编程:

①自己的方法

#pragma warning(disable:4996)
#include <stdio.h>
void main()
{
    int a, b, c;
    printf("input three  numbers\n");
    scanf("%d%d%d", &a, &b, &c);
    if (a < b && b < c)
    {
        printf("%d %d %d",a,b,c);
    }
    else if (a < c && c < b)
    {
        printf("%d %d %d",a,c,b);
    }
    else if (b < a && a < c)
    {
        printf("%d %d %d",b,a,c);
    }
    else if (b < c && c < a)
    {
        printf("%d %d %d",b,c,a);
    }
    else if (c < a && a < b)
    {
        printf("%d %d %d",c,a,b);
    }
    else if (c < b && b < a)
    {
        printf("%d %d %d",c,b,a);
    }
}

②老师的方法

#pragma warning(disable:4996)
#include <stdio.h>
void main()
{
    int a, b, c, temp;
    printf("input three  numbers\n");
    scanf("%d%d%d", &a, &b, &c);
    if (a > b)
    {
        temp = a;
        a = b;
        b = temp;
    }
    if (a > c)
    {
        temp = a;
        a = c;
        c = temp;
    }
    if (b > c)
    {
        temp = b;
        b = c;
        c = temp;
    }
    printf("%d %d %d", a, b, c);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值