【基础题】【分支】排顺序

1.输入四个数,要求按由小到大的顺序输出

#include<iostream>
#include<math.h>
using namespace std;

int main(){
	int a,b,c,d,t;
	cin>>a>>b>>c>>d;
	if(a > b){
		t = a;
		a = b;
		b = t;
	}
	if(a > c){
		t = a;
		a = c;
		c = t;
	}
	if(a > d){
		t = a;
		a = d;
		d = c;
	}
	if(b > c){
		t = b;
		b = c;
		c = t;
	}
	if(b > d){
		t = b;
		b = d;
		d = t;
	}
	if(c > d){
		t = c;
		c = d;
		d = t;
	}
	cout<<a<<" "<<b<<" "
	<<c<<" "<<d;
	return 0;
}
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页