码迷,mamicode.com
首页 > 编程语言 > 详细

C++对三个数进行排序

时间:2014-11-10 21:55:06      阅读:413      评论:0      收藏:0      [点我收藏+]

标签:io   os   sp   as   c++   ios   c   return   class   

#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++对三个数进行排序

标签:io   os   sp   as   c++   ios   c   return   class   

原文地址:http://blog.csdn.net/qq_22335577/article/details/40986143

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!