Find largest of two numbers is c++ program to find largest of two numbers.
In this tutorial we are going to one simple and easy program in cpp programming which is to find largest of two numbers.
How to find largest of two numbers.
First we take two numbers input from user. Then using the condition statement in cpp we write a condition to check which number is large. Depending on that we print the result.
Example :
Number 1 = 10 and number 2 =30
if(number 1 > number 2)
number 1 is large
else
number 2 large
In above example number 1=10 and number 2 =30, then condition is checked number 1 > number 2 condition false so else block true. that is number is large.
Algorithm to find large of two number
- Start
- Declare variables
- Take numbers input from user.
- Write condition to check which number is large
- if first number is large then print number 1 is large.
- else print number 2 large
- End
C++ Program to Find Largest of Two Numbers
123456789101112131415161718192021222324252627282930313233343536373839 | #include <iostream>using namespace std;int main(){ int num1, num2; cout<<“Enter first number:”; cin>>num1; cout<<“Enter second number:”; cin>>num2; if(num1>num2) { cout<<“First number “<<num1<<” is the largest”; } else { cout<<“Second number “<<num2<<” is the largest”; } return 0;} |
Output :

Explanation:
1. Execution starts with the main function.
2. Declare the variables
num1 => to store first number
num2 => to store second number
3. Next we take two input
cin>>num1; => num1= 10
cin>>num2; => num2= 20
4. Next we write the condition to check large number among two
if(num1>num2) => 10 > 20 this condition becomes false and if block skipped
5. and else block get executed
cout<<“Second number “<<num2<<” is the largest”;
=>Second number 20 is the largest