以下是用C语言编写的程序,可以实现输入3个整数并按照从小到大的顺序进行排序:

#include <stdio.h>

void swap(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

void sort(int *a, int *b, int *c) {
    if (*a > *b) {
        swap(a, b);
    }
    if (*a > *c) {
        swap(a, c);
    }
    if (*b > *c) {
        swap(b, c);
    }
}

int main() {
    int a, b, c;

    printf("请输入3个整数:\n");
    scanf("%d %d %d", &a, &b, &c);

    sort(&a, &b, &c);

    printf("排序结果为:%d %d %d\n", a, b, c);

    return 0;
}

运行程序后,会提示用户输入3个整数。然后程序会对这3个整数进行排序,并将结果输出。

C语言实现3个整数排序:简单易懂的代码示例

原文地址: https://www.cveoy.top/t/topic/bxNd 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录