1000. 用指针方法处理数的排序

来源:互联网 发布:什么是物联网大数据 编辑:程序博客网 时间:2024/06/18 10:20
Description

输入3个整数,按从大到小的书序输出。

Input

12 8 23

Output

23 12 8

Sample Input
 Copy sample input to clipboard
10 8 9
Sample Output
10 9 8

Problem Source: 指针

#include<iostream>

using namespace std;
int c[4];
int sort(int *p)
{
 int *a,*b,temp;
 for(a=p;a<p+3;a++)
  for(b=a+1;b<p+3;b++)
   if(*a<=*b)
   {
    temp=*a;
    *a=*b;
    *b=temp;
   }
 for(a=p;a<p+3;a++) cout<<*a<<" ";
}
int main()
{
 for(int i=0;i<3;i++)
 { cin>>c[i];
 }
 sort(c);

 return 0;
}

0 0
原创粉丝点击