Flow Control
C else-if Statements
else if statements in C is like another if condition, it’s used in program when if statement having multiple decisions.
The basic format of else if statement is:
Syntax:
if(test_expression)
{
   //execute your code
}
else if(test_expression n)
{
   //execute your code
}
else
{
   //execute your code
}Example of a C Program to Demonstrate else if Statement
Example:
#include<stdio.h>
main()
{
  int a, b;
  printf("Please enter the value for a:");
  scanf("%d", & amp; a);
  printf("\nPlease enter the value for b:");
  scanf("%d", & amp; b);
  if (a & gt; b)
  {
    printf("\n a is greater than b");
  }
  else if (b & gt; a)
  {
    printf("\n b is greater than a");
  }
  else
  {
    printf("\n Both are equal");
  }
}Program Output:


Comments
Post a Comment