1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
using namespace std;
float getExtremes(float& min, float& max, float a[], int n){
min = max = a[0];
for (int i=1; i<n; i++)
if (a[i] < min)
min = a[i];
else if (a[i] > max)
max = a[i];
return 0;
}
int main(){
int n = 8;
float min,max;
float a[] = {1, 2, 3, 4, 5, 6, 7, 8};
getExtremes(min,max,a,n);
cout << min << endl;
cout << max << endl;
return 0;
}
|