Comprehensive Application of Address Passing and Reference Passing
Input a one-dimensional array in the main function, and call the function maxAndMin to get the maximum and minimum values in the array elements, where the basic framework of the function is:
#include <iostream>
using namespace std;
#define SIZE 10
void maxAndMin(int a[], int& maximum, int& minimum)
{
}
int main()
{
int numbers[SIZE], maxValue, minValue,i;
cout << "Please input " << SIZE << " numbers:";
for(i = 0; i < SIZE ; i++)
cin >> numbers[i];
maxAndMin(numbers, maxValue, minValue);
cout << "The maximum is: " << maxValue << endl;
cout << "The minimum is: " << minValue << endl;
return 0;
}
Complete the content of the maxAndMin function
#include <iostream>
using namespace std;
#define SIZE 10
void maxAndMin(int a[], int& maximum, int& minimum)
{
int i;
maximum=a[0];
minimum=a[0];
for(i=0;i<10;i++)
{
{if(a[i]>maximum)
maximum=a[i];}
{if(a[i]<minimum)
minimum=a[i];}
}
}
int main()
{
int numbers[SIZE], maxValue, minValue,i;
cout << "Please input " << SIZE << " numbers:";
for(i = 0; i < SIZE ; i++)
cin >> numbers[i];
maxAndMin(numbers, maxValue, minValue);
cout << "The maximum is: " << maxValue << endl;
cout << "The minimum is: " << minValue << endl;
return 0;
}