[YTU]_1063 (输入三个整数,按由小到大的顺序输出)
生活随笔
收集整理的這篇文章主要介紹了
[YTU]_1063 (输入三个整数,按由小到大的顺序输出)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Description
輸入三個整數(shù),按由小到大的順序輸出。分別使用指針和引用方式實現(xiàn)兩個排序函數(shù)。在主函數(shù)中輸入和輸出數(shù)據(jù)。
Input
三個整數(shù)
Output
由小到大輸出成一行,每個數(shù)字后面跟一個空格。由指針方式實現(xiàn)。
由小到大輸出成一行,每個數(shù)字后面跟一個空格。由引用方式實現(xiàn)。
Sample Input
2 3 1Sample Output
1 2 3 1 2#include <iostream> using namespace std; void sort1(int*p1,int*p2,int*p3) {void swap1(int *p1,int *p2);if(*p1>*p2)swap1(p1,p2);if(*p1>*p3)swap1(p1,p3);if(*p2>*p3)swap1(p2,p3); } void swap1(int *p1,int *p2) {int temp;temp=*p1;*p1=*p2;*p2=temp; } void sort2(int&r1,int&r2,int&r3) {void swap2(int &,int & );if(r1>r2)swap2(r1,r2);if(r1>r3)swap2(r1,r3);if(r2>r3)swap2(r2,r3); } void swap2(int &R,int &r) {int temp;temp=R;R=r;r=temp; } int main() {void sort1(int *,int *,int *);void sort2(int &,int &,int &);int n1,n2,n3;int *p1,*p2,*p3;int r1,r2,r3;cin>>n1>>n2>>n3;r1=n1;r2=n2;r3=n3;p1=&n1;p2=&n2;p3=&n3;sort1(p1,p2,p3);cout<<n1<<" "<<n2<<" "<<n3<<" "<<endl;sort2(r1,r2,r3);cout<<r1<<" "<<r2<<" "<<r3<<" "<<endl;return 0; }3
總結(jié)
以上是生活随笔為你收集整理的[YTU]_1063 (输入三个整数,按由小到大的顺序输出)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [YTU]_2018 ( 约瑟夫问题)
- 下一篇: [YTU]_1064 (输入三个字符串,