If-else statement

If-else:

It-else statement is used to select one statement and ignore the other statements.

syntax:

if(condition)
s1;
else
s2;

Flow chart:

if else new

 

Example 1

#include<iostream.h>

void main()

{

int a;

cout<“<\n enter a no.”; cin>>a;

if(a%2==0)

cout<<” Even number”;

else

cout<<” Odd number”;

}

Output

Enter a no. 8

Even number.

Example 2

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr(); // Variable Declaration int a1; // Get Input Value cout<<“Enter the Number :”;

cin>>a1; //If Condition Check

if(a1 > 10)

{

// Block For Condition Success

cout<<a1<<” Is Greater than 10″;

}

else

{

// Block For Condition Fail cout<<a1<<” Is Less than/Equal 10″;

}

getch();

}

Output

Enter the Number :6

6 Is Less than/Equal 10

 

Leave a Reply

Your email address will not be published. Required fields are marked *