题目 键盘输入4个整数,从小到大排序
思路
代码
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>//键盘输入4个整数,从小到大排序
int main()
{int n1, n2, n3, n4;scanf_s("%d %d %d %d", &n1, &n2, &n3, &n4);if (n1 > n2){int tmp = n1;n1 = n2;n2 = tmp;}if (n1 > n3){int tmp = n1;n1 = n3;n3 = tmp;}if (n1 > n4){int tmp = n1;n1 = n4;n4 = tmp;}if (n2 > n3){int tmp = n2;n2 = n3;n3 = tmp;}if (n2 > n4){int tmp = n2;n2 = n4;n4 = tmp;}if (n3 > n4){int tamp = n3;n3 = n4;n4 = tamp;}printf("%d %d %d %d ", n1, n2, n3, n4);return 0;
}