How to find greatest of two numbers using if else statement in C++ Language

Introduction: In previous article i explained the program Else if ladder or multiple else if to check character is vowel or consonant in C++ language and How to find greatest of two numbers using conditional operator in C++ Language. In this post i will explain how you can find greatest of two numbers using if else statement in C++ Language.  Concept is very simple. Just check whether first number is greater than the second number or not. if greater, than first number is the greatest number else second number is the greatest number .Let's create a program.

#include<conio.h>
#include<iostream.h>
main()
{
int a,b;
cout<<"Enter first number :  ";
cin>>a;
cout<<"\nEnter second number:  ";
cin>>b;
if(a>b)
{
cout<<a<<" is greatest number";
}
else
{
cout<<b<<" is greatest number";
}
getch();
}
•  Run the program using Ctrl+F9
OUTPUT
Enter first number:  2
Enter second number:  8
8 is greatest number

Previous
Next Post »

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..