Answer to Question #342816 in C++ for Nora

Question #342816

Minimum and Maximum array entry

With a function that take as parameters a one dimensional array and

the capacity of the array. Your function has to find the minimum and

maximum entry in a one dimensional array. Write a driver program that

reads array values and finds the minimum and maximum entry using your

function.

Sample Input/Output:

Enter a no. of array elements: 5

Array[1]: 20

Array[2]: 80

Array[3]: 90

Array[4]: -23

Array[5]: 70

Minimum Array Entry: -23

Maximum Array Entry: 90


1
Expert's answer
2022-05-19T16:41:12-0400
#include <iostream>


using namespace std;


int main()
{
	int n;
	cout << "Enter a no. of array elements: ";
	cin >> n;
	int* arr = new int[n];
	for(int i =0;i<n;i++)
	{
		cout << "Array[" << i + 1 << "]: ";
		cin >> arr[i];
	}
	int minim = arr[0];
	int maxim = arr[0];
	for (int i = 0; i<n; i++)
	{
		if (arr[i] < minim)
			minim = arr[i];
		if (arr[i] > maxim)
			maxim = arr[i];
	}
	cout << "Minimum Array Entry: " << minim<<endl;
	cout << "Maximum Array Entry: " << maxim;
	delete[]arr;
}

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