实现函数void mymax1(int x,int y,int z,int *max, int *min)和void mymax2(int x,int y, int z, int &max , int &min) 求三个数的最大值和最小值。
时间: 2023-05-31 12:04:05 浏览: 92
*max, int *min),分别返回x、y、z中的最大值和最小值。
方法一:
void mymax1(int x, int y, int z, int *max, int *min)
{
if(x >= y && x >= z)
{
*max = x;
if(y >= z)
{
*min = z;
}
else
{
*min = y;
}
}
else if(y >= x && y >= z)
{
*max = y;
if(x >= z)
{
*min = z;
}
else
{
*min = x;
}
}
else
{
*max = z;
if(x >= y)
{
*min = y;
}
else
{
*min = x;
}
}
}
方法二:
void mymax2(int x, int y, int z, int *max, int *min)
{
int temp;
*max = x;
*min = x;
if(y > *max)
{
*max = y;
}
if(z > *max)
{
*max = z;
}
if(y < *min)
{
*min = y;
}
if(z < *min)
{
*min = z;
}
}
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)