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
#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;
}
Comments
Leave a comment