











C++ Program to Find Greatest of Two Numbers
Algorithm:-
- Take Two inputs for comparison
- The inputs are stored in two int type variables say first and second respectively.
- The two inputs are compared using the if else statement with the condition:
- if( first > second )
- If the above mentioned condition is true then first is greater than the second.
- Otherwise second is greater than the first.
C++ Code:-
//C++ program
//Greatest of two numbers
#include<iostream>
using namespace std;
//main program
int main()
{
int first,second;
cout<<“Enter first number: “;
cin>>first;
cout<<“Enter second number: “;
cin>>second;
if(first==second)
{
cout<<“both are equal”;
}
else if(first>second)
{
cout<<first<<” is greater than “<<second;
}
else
{
cout<<second<<” is greater than “<<first;
}
return 0;
}
Output:-
Output
Enter first number: 11
Enter second number: 97
97 is greater than 11
- Positive or Negative number: C | C++ | Java
- Even or Odd number: C | C++ | Java
- Sum of First N Natural numbers: C | C++ | Java
- Sum of N natural numbers: C | C++ | Java
- Sum of numbers in a given range: C | C++ | Java
- Greatest of two numbers: C | C++ | Java
- Greatest of the Three numbers: C | C++ | Java
- Leap year or not: C | C++ | Java
- Prime number: C | C++ | Java
- Prime number within a given range: C | C++ | Java
- Factorial of a number: C | C++ | Java
- Sum of digits of a number: C | C++ | Java
- Reverse of a number : C | C++ | Java
- Palindrome number: C | C++ | Java
- Armstrong number : C | C++ | Java
- Armstrong number in a given range : C | C++ | Java
- Fibonacci Series upto nth term : C | C++ | Java
- Factorial of a number : C | C++ | Java
- Power of a number : C | C++ | Java
- Factor of a number : C | C++ | Java
- Strong number : C | C++ | Java
- Perfect number : C | C++ | Java
- Automorphic number : C | C++ | Java
- Harshad number : C | C++ | Java
- Abundant number : C| C++ | Java
- Friendly pair : C | C++ | Java


Login/Signup to comment