C++ Programming Code Examples C++ > Sorting Searching Code Examples Find maximum and minimum number in array c++ code Find maximum and minimum number in array c++ code Write a program to find maximum and minimum number in array using for loop and if statement. To initialize array use random numbers Program should display all random elements of array and minimum and maximum number in array on the output console. Array size is fixed to 100 to change the size just change the value of size integer In the for loop array is initializing with a random number less than 100 to change the range just replace 100 by any desired number and it will produced numbers between 0 to a number you replaced In another for loop which programs go through from start of the array to the end and with contains two if statements which checks for both minimum and maximum number in array #include<iostream> #include<cstdlib> #include<ctime> using namespace std; int main() { const int size=50; // array with size of 50 int array[size]; // for random numbers srand(time(0)); for(int i=0;i<size;i++){ // Initializing Array number is less than 100 array[i]=rand()%100; // Displaying array value cout<<array[i]<<endl; } // initializing max, min int max=array[0]; int min=array[0]; /* scanning array to find minimum and maximum number */ for(int i=0;i<size;i++){ // finding minimum number in array if(min>array[i]){ min=array[i]; } //finding maximum number in array if(max<array[i]){ max=array[i]; } } // displaying output cout<<"Maximum Number is :"<<max<<endl; cout<<"Minimum Number is:"<<min<<endl; return 0; }