两个数:
void Sawp(int *p1,int *p2)
{
int tmp;
tmp=*p1;
*p1=*p2;
*p2=tmp;
int main()
{
int a=10;
int b=20;
Sawp(&a,&b);
printf("%d %d\n",a,b);
return 0;
}
三个数:
#include<bits/stdc++.h>
using namespace std;
int main(){
void Three_sort(int *a,int *b,int *c);
int a,b,c;
cin>>a>>b>>c;
Three_sort(&a,&b,&c);
cout<<a<<b<<c;
return 0;
}
void Three_sort(int *a,int *b,int *c)
{
int t;
if(*a>*b)
{t=*a;*a=*b;*b=t;}
if(*a>*c)
{t=*a;*a=*c;*c=t;}
if(*b>*c)
{t=*b;*b=*c;*c=t;}
}