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;


Do you like this post? Please link back to this article by copying one of the codes below.

URL Of Post:

HTML Link Code:

BB (forum) link code: