輸入三個整數,按從大到小順序輸出
阿新 • • 發佈:2019-02-19
執行結果:/* * Copyright (c) 2012, 煙臺大學計算機學院 * All rights reserved. * 作 者: 胡穎 * 完成日期:2012 年12月20日 * 版 本 號:v1.0 * * 輸入描述:輸入三個整數 * 問題描述:略 * 程式輸出:輸出按從小到大排列的整數 * 問題分析:略 */ #include <iostream> using namespace std; void sort(int*x,int*y); void exchange(int*p1,int*p2,int*p3); int main(void) { void sort(int *p1,int *p2,int *p3); int a,b,c; cout<<"請輸入三個正整數:"<<endl; cin>>a>>b>>c; sort(&a,&b,&c); cout<<"從大到小排列為:"<<a<<'\t'<<b<<'\t'<<c<<endl; return 0; } void sort(int *p1,int *p2,int *p3) { void exchange(int *,int *); if(*p1<*p2) exchange(p1,p2); if(*p1<*p3) exchange(p1,p3); if(*p2<*p3) exchange(p2,p3); } void exchange(int *x,int *y) { int tem; tem=*x; *x=*y; *y=tem; }