F How To Find Min and Max Value From User Input Number Using Array | CodeTheta

How To Find Min and Max Value From User Input Number Using Array

February 26, 2016

Below program uses 5 integer data type variable.
maximum : This will find the biggest element through out the numbers.
minimum : This will find the smallest element through out the numbers.
n : This will be user input number.
i : This will use for loop method.
Array[10] : This is a array where all the elements are stored.
At the starting stage of the program array value is initialized to 0.

/* http://native-code.blogspot.com */
#include<iostream>
using namespace std;
int main()
{
int Array[10],i,n,maximum,minimum;
cout<<"/* http://native-code.blogspot.com */"<<endl;
cout<<"Enter array size: ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter array value:";
cin>>Array[i];
}
minimum=Array[0];
maximum=Array[0];
for(i=0;i<n;i++)
{
if(Array[i]>maximum)
maximum=Array[i];
if(Array[i]<minimum)
minimum=Array[i];
}
cout<<"Maximum element is: "<<maximum<<endl;
cout<<"Minimum element is: "<<minimum;
return 0;
}

IDE Used To Test This Code : Dev C++.
Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

Post a Comment