1. Write a function that displays the maximum and minimum of a list of numbers entered from the keyboard. Where the size of the list is to be entered from the keyboard.
#include <iostream>
using namespace std;
void printmaxmin(int n,const float* ar){
int max, min;
max = min = ar[0];
for(int i = 0; i < n; i++){
if(ar[i] > max){
max = ar[i];
} else if(ar[i] < min){
min = ar[i];
}
}
cout << "min "<< min<<endl<<"max "<<max<<endl;
}
int main(){
int n, max, min;
float *ar;
cout << "enter size: " << endl;
cin >> n;
ar = new float[n];
for(int i = 0; i < n; i++){
cin >> ar[i];
}
printmaxmin(n, ar);
}
Comments
Leave a comment