C++ Program to Find Greatest of Two Numbers

Program to find 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)

Competitive Coding Techniques

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

Greatest of Two Numbers in C++

C++ Code

using namespace std;
int main()
    int a,b;
    cout<<"Enter first number: "; cin>>a;
    cout<<"Enter second number: "; cin>>b;
            cout<<"both are equal"; } else if(a>b)
            cout<<a<<"is greater than "<<b;
            cout<<b<<"is greater than "<<a;
        return 0;


Enter first number: 2
Enter second number: 2
both are equal