/*
* Copyright (c) 2013, 烟台大学计算机学院
* All rights reserved.
* 作 者:申玉迪
* 完成日期:2013 年 12 月 17 日
* 版 本 号:v1.0
* 输入描述: 无
* 问题描述:用指针排序3个数
*/
#include <iostream>
using namespace std;
void paixu(int *a,int *b,int *c);
void jiaohuan(int *x,int *y);
int main()
{
int a,b,c;
cin>>a>>b>>c;
paixu(&a,&b,&c);
cout<<"排序后的值为:"<<a<<">"<<b<<">"<<c<<endl;
return 0;
}
void paixu(int *a,int *b,int *c)
{
if(*a<*b)
jiaohuan(a,b);
if(*a<*c)
jiaohuan(a,c);
if(*b<*c)
jiaohuan(b,c);
}
void jiaohuan(int *x,int *y)
{
int t;
t=*x;
*x=*y;
*y=t;
}
十七周——3个数排序(指针)
最新推荐文章于 2024-01-17 19:46:37 发布