Monday, 7 April 2014

If-Else Statement in C

 If-Else statement execute one of two statements, if true one or group of statements will execute, if false executes another one or group of statements.

The If statement by itself will execute a single statement, or a group of statements, when the test expression is true. It does nothing when it is false. We can execute a group of statements if and only if the test expression is not true. Its Syntax is:
if( condition)
statement;
else
statement;

Lets have a look at the following example:

Program
void main ( )
{
char ch;
ch= getche( );
if (ch = = 'y' )
printf(" You entered y");
else
printf(" You did not entered y");
}

Output
y
You entered y

n
You did not entered y






No comments:

Post a Comment