C++ If-else statement
C++ If-else statement
This statement has a single section, but it has two blocks.
One is true block and the other is false block.
In this condition is checked first. If it is true, then the program control flow goes inside
the braces and executes the block of statements associated with it. If it returns false,
then it executes the else part of a program.
Syntax :
if(condition)
{
true statements;
}
else
{
false statements
}
Example :
#include <iostream.h>
#include <conio.h>
void main()
{
int no;
clrscr();
cout << "\n Enter Number :";
cin>>no;
if(no%2==0)
cout << "\n\n Number is even !";
else
cout << "\n\n Number is odd !";
getch();
}
Output :
When user enter 11 the if condition becomes false and hence the else statement is executed.
Labels:
C++ If-else statement,
if-else statement
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment