What Is If-Else Statement In C Language?

 What Is If-Else Statement In C Language?

what is if-else statement in c language


Hello Programmers,

Today we will discuss the 'if-else' statement. In the last blog, we studied 'if' statement. These if-clauses are very important in c language. 


if-else statement: 


if-else statement is meant to perform one block of statement out of possible two blocks of statements depending on the result of a condition.


Syntax:


if(condition)
{
    Statement block-1;
}
else
{
    Statement block-2;
}

In upper syntax, the statement block -1 is executed when 'if' condition is true. If the condition is false then else block is executed then statement block-2 is executed.



Flow Chart:



if-else statement in c language

The program which used if-else: 

#include<stdio.h>
#include<conio.h>

void main()
{
    int age;
   clrscr();

   printf("Enter your age");
   scanf("%d",&age);

   if(age>20)
    {
        printf("You are eligible for this game"  );
    }
  else
   {
        printf(" You are not eligible for this game");
    }

getch();
}


Output:

 
Run1: 
            Enter your age: 21
            You are eligible for this game 

Run2: 
            Enter your age: 19
            You are not eligible for this game 




Sharing Is Caring...

Comments :

Post a Comment