Saturday 22 December 2018

else-if or Ladder if statement


else-if or Ladder if statement :
                                                         In this, first condition will be checked, if it is true then the corresponding statements will be executed otherwise further next condition will be checked and this process will continue till the end of the condition. The flowchart and the syntax of else-if is shown below:
Ex:          void main()
{
       int code;
                                    clrscr();            
                                       printf(“Enter the code(1-3):”);
                                       scanf(“%d”,&code);
                                       if(code==1)
                                       {
                                                printf(“PINK”);
                                       }
                                       else if(code==2)
                                      {                       
                                                printf(“RED”);
                                      }                                                                          
                                      else if(code==3)
                                      {
                                                printf(“BLUE”);
                                      }
                                      else
                                      {
                                                printf(“\n Invalid code”);
                                      }
                                       printf(“\n End of the program”);
                                       getch();
                                       }



No comments:

Post a Comment