输入4个整数,要求按由小到大的顺序输出 C++源代码

2016-06-16 10:54:54  分类: c++程序设计第三版谭浩强课后答案  参与:

输入4个整数,要求按由小到大的顺序输出   C++源代码

【c++源代码】
#include <iostream>
using namespace std;
int main ()
{int t,a,b,c,d;
 cout<<"enter four numbers:";
 cin>>a>>b>>c>>d;
 cout<<"a="<<a<<", b="<<b<<", c="<<c<<",d="<<d<<endl;
 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=t;}
 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<<"the sorted sequence:"<<endl;
 cout<<a<<", "<<b<<", "<<c<<", "<<d<<endl;
 return 0;
 }

 
 

来源:c++程序设计第三版谭浩强课后答案

本文链接:http://www.wb98.com/cjia/post/cjia_3.14.html


本站文章搜索:

<< 上一篇下一篇 >>

搜索

Tags列表

赞助商链接