浙大版《C语言程序设计(第3版)》题目集 习题3-1 比较大小 (10分)

在这里插入图片描述

c:

#include <stdio.h>
int main(void)
{
    int a, b, c, t;
    scanf("%d %d %d", &a, &b, &c);
    if (a > b)
    {
        t = a;
        a = b;
        b = t;
    }
    if (a > c)
    {
        t = a;
        a = c;
        c = t;
    }
    if (b > c)
    {
        t = b;
        b = c;
        c = t;
    }
    printf("%d->%d->%d", a, b, c);
    return 0;
}

c++:

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int a[3], i, j;
    for(i = 0; i < 3; i++)
    {
        scanf("%d", &a[i]);
    }
    sort(a, a+3);
    printf("%d->%d->%d", a[0], a[1], a[2]);
    return 0;
}
发布了161 篇原创文章 · 获赞 117 · 访问量 6015

猜你喜欢

转载自blog.csdn.net/qq_44458489/article/details/105281891