C++ Program to Find Largest Number Among Three Numbers

In this program, you will learn about how to find the largest number among the three numbers in the cpp programming language.


Code:

#include <iostream>

using namespace std;


int main()

{

int var1,var2,var3;


cout<<" Enter the first number "<<endl;

cin>>var1;

cout<<" Enter the second number "<<endl;

cin>>var2;

cout<<" Enter the third number "<<endl;

cin>>var3;


if(var1>=var2 && var1>=var3)

{

cout<<" this is largest number = "<<var1<<endl;

}

if(var2>=var1 && var2>=var3)

{

cout<<" this is largest number = "<<var2<<endl;

}

if(var3>=var2 && var3>=var1)

{

cout<<" this is largest number = "<<var3<<endl;

}


    return 0;

}

Output:

 Enter the first number

5

 Enter the second number

6

 Enter the third number

7

 this is largest number = 7

Here, compare the first variable by other two variables in the first if statement if(var1>=var2 && var1>=var3) .In the same way, apply the other two if statement on the others two variables by comparing three variables.

If you have any query about the above article please write your query in below comment section.



Comments

Popular posts from this blog

how to cout in cpp

Flutter layout

Diferrence between flutter and react native