IF ELSE in C++
IF ELSE
The keyword else is used to specify two different choices with if statement. the general form of if else statement is:
if(condition)
{
block of if(true case)
}
else
{
block of else(false case)
}
if the condition is true, the block of if statement is executed and if the condition is false ,the block of else statement is executed.
Program:
#include <iostream>
using namespace std;
void main()
{
float no_1,no_2=0.0;
cout<<"Enter 1st number:";
cin>>no_1;
cout<<"Enter 2nd number:";
cin>>no_2;
if(no_1>no_2)
cout<<no_1<<" is Largest Number";
else if(no_2>no_1)
cout<<no_2<<" is Largest Number";
else if(no_1 == no_2)
cout<<"Both are Same";
else
cout<<"Invalid Input"<<endl;
system("pause");
}
Comments
Post a Comment