首页 > 代码库 > C++对三个数进行排序

C++对三个数进行排序

#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cout<<"请输入三个数"<<endl;
	cin>>a>>b>>c;
	if(a>b)
	{
		if(a>c)
		{
			if(b>c)
			{
				cout<<"三个数的从小到大的排序为"<<endl;
				cout<<a<<" "<<b<<" "<<c<<endl;

			}
			else
			{
				int tmp=a;
				b=c;c=tmp;
				cout<<"三个数的从小到大的排序为"<<endl;
				cout<<a<<" "<<b<<" "<<c<<endl;
			}
		}
		else
		{
			int tmp1,tmp2;
			tmp1=a;
			tmp2=b;
			a=c;
			b=tmp1;
			c=tmp2;
			cout<<"三个数的从小到大的排序为"<<endl;
				cout<<a<<" "<<b<<" "<<c<<endl;
		}
	}
	else
	{
		if(b>c)
		{
			if(a>c)
			{
				int tmp1=a;
				int tmp2=b;
				a=b;
				b=tmp1;
				cout<<"三个数的从小到大的排序为"<<endl;
				cout<<a<<" "<<b<<" "<<c<<endl;
			}
			else
			{
				int tmp1=a;
				int tmp2=b;
				a=b;
				b=c;
				c=tmp1;
				cout<<"三个数的从小到大的排序为"<<endl;
				cout<<a<<" "<<b<<" "<<c<<endl;
			}
		}
		else
		{
			int tmp1=a;
			int tmp2=b;
			a=c;
			c=tmp1;
			cout<<"三个数的从小到大的排序为"<<endl;
				cout<<a<<" "<<b<<" "<<c<<endl;
		}
	}
	system("pause");
	return 0;
}

C++对三个数进行排序