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 ‘>


  • Two inputs are taken from user.
  • The inputs are stored in two int type variables say first and second respectively.
  • The two inputs are compared using the if else statement with the condition:

                    if( first > second )

  • If the above mentioned condition is true then first is greater than the second.

Otherwise second is greater than the first.

C++ Program to find the Greatest of two numbers

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

Please Login/Signup to comment