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;
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
  • 2022-01-03
  • 2022-02-01
  • 2022-12-23
猜你喜欢
  • 2022-01-26
  • 2021-07-16
  • 2021-05-30
  • 2022-12-23
  • 2022-12-23
  • 2021-04-14
  • 2021-12-22
相关资源
相似解决方案