×
☰ Menu

Nested if-else statement

 

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.

              

 Sample Program on Nested if-else Statement

void main()
{
    int per;
    printf("enter per:\n");
    scanf("%d",&per);
    if ( per >= 60 )
    printf ( "First division" ) ;
    else
    {
        if ( per >= 50 ) 
        printf ( "Second division" ) ;
        else
            {
               printf ( "Fail" ) ;
            }
    }
    getch();
}