Answer to Question #258315 in C++ for Alemnat

Question #258315

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.



1
Expert's answer
2021-10-29T00:53:40-0400
#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);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS