C++ Program to Find Largest and Smallest Number in Array

The c++  program below generates a random number and stores it in an array, then  passes an array to a function which calculates the maximum and minimum number in the array and displays it.

Also Read: C++ Program to Find All The Roots Of A Quadratic Equation

How the program works:

  • Declare array of size 10
  • Using for loop assign array indexes with random values between 1 and thousand
  • Call the function and pass array and its size as argument
  • Function declares two integers max and min and assign both integers with arrays first index value
  • Then with in for loop there are two if condition first check is for minimum number and second check is for maximum number
  • Finally program display the output values of both integers min and max

Also Read: C++  Program For Binary Equivalent Of a Decimal Number
                 C++ Program to Check If a Number Is A Perfect Number or Not

#include <iostream.h>
#include <stdlib.h>

void FindMaxMin(int *array, int size)
     int min,max;
            for(int i=1;i<size;i++)
                else if(array[i]>max)
 cout<<"Minimum Number  = "<<min<<endl;
 cout<<"Maximum Number = "<<max<<endl;
int main()
     int array[10];
     for(int i=0;i<=9;i++)
         cout<<"array ["<<i<<"]"<<"= "<<array[i]<<endl;
return 0;



Tech blogger, SEO expert, cryptocurrency enthusiast, and freelancer are the terms that describe me. I'll rather write a thousand words than speak hundred words, and that describes my passion as a content creator.