Thursday, 2 March 2017

Elements of programming-6




If-else if ladder.

Checking more than one else if condition is known as if-else if ladder. First a condition is checked if it is true then a block of statements are executed. If it is false an another condition is checked with the help else if construct. If it also false then another condition is checked. Checking more than one else if construct is known as else if ladder.


Example:

#include <stdio.h>

int main()
{
    int dayno;
    printf("enter day no:");
    scanf("%d",&dayno);
    if(dayno==1)
    {
        printf("sunday");
    }
   else  if(dayno==2)
    {
        printf("monday");
    }
   else if(dayno==3)
    {
        printf("tuesday");
    }
   else if(dayno==4)
    {
        printf("wednesday");
    }
    else if(dayno==5)
    {
        printf("thursday");
    }
   else if(dayno==6)
    {
        printf("friday");
    }
   else if(dayno==7)
    {
        printf("saturday");
    }
    else
    {
        printf("invalid day number");
    }


    return 0;
}

                                       In the above program day number is get as input . the block statements which will be executed is depending upon the variable dayno we entered. If all the condition is false then  else part will be executed.

                                       Thanking you,
                                                                    Muthu karthikeyan,Madurai.
contact:919629329142
email:muthu.vaelai@gmail.com

No comments:

Post a Comment