C++ Program to Find Greatest of Two Numbers

Program to find the Greatest of two numbers

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

To find greatest of two numbers the use of if else statement is required along with the relational operator ‘>’ (greater than operator)

C++ Program to Find Greatest of Two Numbers


  1. Take Two inputs for comparison
  2. The inputs are stored in two int type variables say first and second respectively.
  3. The two inputs are compared using the if else statement with the condition:
    1. if( first > second )
  4. If the above mentioned condition is true then first is greater than the second.
  5. Otherwise second is greater than the first.

C++ Code:-

    //C++ program
    //Greatest of two numbers
    using namespace std;
    //main program
    int main()
        int first,second;
        cout<<“Enter first number: “;
        cout<<“Enter second number: “;
            cout<<“both are equal”;
        else if(first>second)
            cout<<first<<” is greater than “<<second;
            cout<<second<<” is greater than “<<first;
        return 0;



    Enter first number: 11
    Enter second number: 97
    97 is greater than 11