else-if





if...else if condition

The if-else-if Ladder. A common programming construct that is based upon nested ifs is the if-else-if ladder. It looks like this. The conditional expressions are evaluated from the top downward. As soon as a true condition is found,



syntax
if(condition1)
{
   statement
}
else if(condition2)
{
   statement
}
--------------------------
--------------------------
else
{
  default statement
}



Flow chart





Example for if...else if condition in[c-program]


#include< stdio.h > /* header file */
#include< conio.h > /* header file */

void main() /* main function start*/
{
  int mark;

  clrscr();

  printf("enter the mark \n ");
  scanf("%d",&mark);


  if(mark<=30)
  {
         printf("fail & very low mark\n");
  }

   else if(mark<=50)
    {
        printf("pass & better mark\n");
    }

  else if(mark<=70)
   {
        printf("pass & good mark\n");
   }
  else if(mark<=95)
   {
        printf("pass & very good mark\n");
   }
  else if(mark>100)
   {
        printf("please enter a correct mark");
   }
  else
   {
       printf("excelent mark");
   }
   getch();
}




youtube tutorial



Comments

Popular posts from this blog

operators in c program

nested-if

switch-statement