C++使用指針將3個整數進行比較大小
任務描述
輸入3個整數,按由小到大的順序輸出(要求用指針或引用方法處理)。
測試輸入:
4 91 51
預期輸出:
4 51 91
測試輸入:
5 1 151
預期輸出:
1 5 151
源代碼:
#include <stdio.h>
#include <iostream>
using namespace std;
void mycmp(int x,int y,int z);
int main()
{
// 請在此添加代碼
/********** Begin *********/
int x,y,z;
cin>>x>>y>>z;
mycmp(x,y,z);
/********** End **********/
return 0;
}
void mycmp(int x,int y,int z){
int temp;
if(x>y){
temp = x;
x = y;
y = temp;
}
if(x>z){
temp = x;
x = z ;
z = temp;
}
if(y>z){
temp = y;
y = z;
z = temp;
}
cout<<x<<" "<<y<<" "<<z;
}