Showing posts with label AF.Condition control. Show all posts
Showing posts with label AF.Condition control. Show all posts

if else condition

if condition in c programming is used in many ways. it is used to check wheather condition satisfies or not. in if function if condition satisfies true block is executed and if condition is false false block is executed.
Syntax:
if(condition)
{
           true block;
}
else
{
          false block;
}
EXAMPLE PROGRAM FOR IF ELSE CONDITION:
#include<stdio.h>
#include<conio.h>
main()
{
      int a;
      clrscr();
      printf("Enter number: ");
      scanf("%d",&a);
      if(a==5)
      {
          printf("\nCondition is true");
      }
      else
      {
          printf("\nCondition is false");
      }
      getch();
}

Else if condition

in else if condition we can put more than 2 possiblities.
SYNTAX:
if(condition)
{
         statements;
}
else if(condition)
{
         statements;
}
else if(condition)
{
         statements;
}
.
.
.
.
else
{
         statements;
}
EXAMPLE FOR ELSE IF:
#include<stdio.h>
#include<conio.h>
main()
{
       int a;
       clrscr();
       printf("Enter Number: ");
       scanf("%d",&a);
       if(a==1)
       {
               printf("\nYou have entered 1");
       }
       else if(a==2)
       {
               printf("\nYou have entered 2");
       }
       else if(a==3)
       {
                  printf("\nYou have entered 3");
       }
       else
       {
                  printf("\nYou have Entered less than 1 or greater than 3");
       }
       getch();
}