C++ Program to find the Greatest of three numbers

Program to find the Greatest of Three Numbers

Here we will discuss how to find the greatest of three numbers entered by the user in c++ programming language.

To find the greatest of three numbers if else-if statement is used along with ‘>’ ad ‘&&’ operator in the condition. 

c++ program to find greatest of three number
Competitive Coding Techniques


  1. Take three numbers as inputs.
  2. The inputs are stored in three int type variables say first, second and third.
  3. The inputs are then compared using the if else if statements   
  4. If the below stated statement is true then first is the greatest.

                             if((first > second) &&(first > third))

      5. Otherwise another conditioned is checked which gives second as the greatest.

                             else if((second > first) && (second > third))

      6. Else third is the greatest of the three.

Greatest of three numbers in C++

C++ Code

//C++ Program
//Greatest of three numbers
using namespace std;

//main program
int main()
    // declare three variable
    int first, second, third;
    // ask user to enter first number
    cout<<"Enter first number: ";
    //ask user to enter second number
    cout<<"Enter second number: ";
    //ask user to enter third number
    cout<<"Enter third number: ";

    //comparing first with other numbers
    if((first >= second) && (first >= third))
            cout<<first<<" is the greatest";

    //comparing Second with other numbers
    else if((second >= first) && (second >= third))
            cout<<second<<" is the greatest";
            cout<<third<<" is the greatest";
    return 0;


Enter first number: 2
Enter second number: 3
Enter third number: 4
4 is the greatest