本文主要是介绍键盘输入4个数,从小到大排序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目 键盘输入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;
}
运行结果
这篇关于键盘输入4个数,从小到大排序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!