鱼C论坛

 找回密码
 立即注册
查看: 3575|回复: 0

刚学指针,大神能不能帮忙看看

[复制链接]
发表于 2013-4-21 00:02:13 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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     
}


小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-8-2 10:16

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表