|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<iostream>
using namespace std; //程序最后是a<b<c的
void sort1(int a,int b,int c);
void sort2(int &a;int &b;int &c);
void sort3(int *a;int *b;int *c);
void main()
{
cout<<"请输入a,b,c的值:"<<endl;
cin>>a>>b>>c;
sort1(a,b,c);
cout<<"sort1函数结果为:"<<"a="<<a<<"b="<<b<<"c="<<c<<endl;
cout<<"请输入a,b,c的值:"<<endl;
cin>>a>>b>>c;
sort2(a,b,c);
cout<<"sort2函数结果为:"<<"a="<<a<<"b="<<b<<"c="<<c<<endl;
cout<<"请输入a,b,c的值:"<<endl;
cin>>a>>b>>c;
sort3(&a,&b,*&c);
cout<<"sort3函数结果为:"<<"a="<<a<<"b="<<b<<"c="<<c<<endl;
}
void sort1(int a,int b,int c)
{
int temp;
if(a>b)
temp=a;
a=b;
b=temp; //使a<=b
if(a>c)
temp=a;
a=c;
c=temp; //使a<=c
if(b>c)
temp=b;
b=c;
c=temp; //使b<=c
}
void sort2(int &a;int &b;int &c)
{
int temp;
if(a>b)
temp=a;
a=b;
b=temp; //使a<=b
if(a>c)
temp=a;
a=c;
c=temp; //使a<=c
if(b>c)
temp=b;
b=c;
c=temp; //使b<=c
}
void sort3(int *a;int *b;int *c)
{
int temp;
if(*a>*b)
temp=*a;
*a=*b;
*b=temp; //使*a<=*b
if(*a>*c)
temp=*a;
*a=*c;
*c=temp; //使*a<=*c
if(*b>*c)
temp=*b;
*b=*c;
*c=temp; //使*b<=*c
}
|
|