Nested if-else It is perfectly all right
if we write an entire if-else construct within either the body of the
if statement or the body of an else statement. This is called
‘nesting’ of ifs. This is shown in the following program.
/* A quick demo of nested if-else */
#include<stdio.h>
/* A quick demo of nested if-else */
#include<stdio.h>
int main( )
{
int i ;
printf ( "Enter either 1 or 2 " ) ;
scanf ( "%d", &i ) ;
if ( i == 1 )
printf ( "You would go to heaven !" ) ;
else
{
if ( i == 2 )
printf ( "Hell was created with you in mind" ) ;
else
printf ( "How about mother earth !" ) ;
}
{
int i ;
printf ( "Enter either 1 or 2 " ) ;
scanf ( "%d", &i ) ;
if ( i == 1 )
printf ( "You would go to heaven !" ) ;
else
{
if ( i == 2 )
printf ( "Hell was created with you in mind" ) ;
else
printf ( "How about mother earth !" ) ;
}
return 0;
}
0 comments:
Post a Comment
Hey this is a test comment