C++_按大小输出三个数

伪码: 

ORDER(n1,n2,n3,pointer1,pointer2,pointer3)  //输入3个数a,b,c按大小顺序输出//

  1. input(n1,n2,n3)                                //输入元素//
  2. data(pointer1)<-n1;(pointer2)<-n2;(pointer3)<-n3                  //pointer1,pointer2,pointer分别指向n1,n2,n3//
  3. if(n1>n2)
  4. then SWAP (pointer1,pointer2)
  5. if(n1>n3)
  6. then SWAP(pointer1,pointer3)
  7. if(n2>n3)
  8. then SWAP(pointer2,pointer3)                    //排序//
  9. output(n1,n2,n3)                                //输出//
  10. return

SWAP(p1, p2)                           //交换数据//

  1. p=p1;p1=p2;p2=p
  2. return

测试用例:n1,n2,n3:4,3,5

测试结果:the sorted numbers are:3        4       5

源程序:

#include"iostream"

using namespace std;

int main()

{

      int n1,n2,n3,t;

      cout<<"please input 3 number:n1,n2,n3:";

      cin>>n1>>n2>>n3;

      if(n1>n2)

      {

            t=n1;

            n1=n2;

            n2=t;

      }

      if(n1>n3)

      {

            t=n1;

            n1=n3;

            n3=n1;

      }

      if(n2>n3)

      {

            t=n2;

            n2=n3;

            n3=t;

      }

      cout<<"the sorted numbers are:"<

 

你可能感兴趣的:(C++)