C++ Program to Find Largest Number Among Three Numbers (Using if-else statement)

by | Jan 13, 2023 | C++, C++ Programs


This program of C++ programming will find the largest number among the three numbers entered by the user.

Here we will use the if-else statement.

Moreover, to understand this program, you should know about

1. Operators

2. if-else statement


using namespace std;
int main()
float x,y,z;
cout<<"Enter three values\n";

if( (x>=y)&&(x>=z))
cout<<x<<" is greatest among all."<<endl;

else if( (y>=x)&&(y>=z))
cout<<y<<" is greatest among all."<<endl;

cout<<z<<" is greatest among all."<<endl;
return 0;




The program asks the user to enter three values, and that values get stored in ‘x’, ‘y’, and ‘z’.

The values entered by the user are x=25, y=25, and z=10.

if( (x>=y)&&(x>=z))

The above if statement gives a true result i.e., 25>=25 && 25>=10

Thus, 25 is the greatest among all.

If in case it gives a false result, then the control moves to the else if statement and work accordingly.




Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.