# 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.   ## Algorithm:-

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. ## C++ Code

```//C++ Program
//Greatest of three numbers
#include<iostream>
using namespace std;

//main program
int main()
{
// declare three variable
int first, second, third;

// ask user to enter first number
cout<<"Enter first number: ";
cin>>first;

//ask user to enter second number
cout<<"Enter second number: ";
cin>>second;

//ask user to enter third number
cout<<"Enter third number: ";
cin>>third;

//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";
}
else
{
cout<<third<<" is the greatest";
}

return 0;
}```

### Output

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