if……else statements in C++

by Nideesh C on May 7, 2011 · 0 comments

in C++




In the if ….else construct, two block of statements are specified, one for the if and the other for the else part. The block of statements in the if are executed if the condition specified results are true. The block present in the else part will be executed, if the specified condition in the if results to false. See the figure below.

If else statements

Syntax:

if (condition)

{

Statements;

.

.

}

else

{

Statements;

.

.

}

Eg:

if (a>b)

cout<<” a is big “;

else

cout<<” b is big “;

/*——————————————————————–*/

#include<iostream.h>

#include<conio.h>

void main()

int a,b ;

cout<<”Enter values for a and b : “;

cin>>a>>b;

if (a>b)

cout<<endl<<” a is big “;

else

cout<<endl<<” b is big “;

getch();

}

/*—————————————————————————-*/

Output:

Enter values for a and b : 100    20

a is big

See also: Nested if statements in C++


 

 

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. Simple IF statement in C++
  2. C++ program – To check whether x is greather than y (IF statement)
  3. if statement in C++
  4. Operators in C++
  5. Sample – understanding call-by-value and call-by-reference

Leave a Comment

Previous post:

Next post: