输入10个整数,将其中最小的数与第一个数对换,把最大的数与最后一个数对换。写三个函数。。。用指针做题
作者:互联网
#include<iostream>
using namespace std;
int main()
{
void input(int* number);
void max_min(int* number);
void output(int* number);
int num[10];
input(num);
max_min(num);
output(num);
return 0;
}
void input(int* number)
{
cout << "pleas enter 10 number:";
for (int i = 0; i < 10; i++) {
cin >> number[i];
}
}
void max_min(int* number)
{
int* max, * min, * p;
max = min = number;
int temp;
for (p=number; p<number+10;p++) {
if (*p > *max) max = p;
}
temp = *max; *max = number[9]; number[9] = temp;
for (p = number; p < number + 10; p++) {
if (*p < *min) min = p;
}
temp = *min; *min = number[0]; number[0] = temp;
}
void output(int* number)
{
for (int i = 0; i < 10; i++) {
cout << number[i] << " ";
}
}
标签:10,temp,min,int,max,void,对换,number,指针 来源: https://blog.csdn.net/weixin_58346553/article/details/117375621