if – else statement

if-else statement is used when a unit of code to be executed by a condition true or false. See the example C program below.

#include<stdio.h>
int main()
{

int   marks;

printf(“Enter the marks\n”);
scanf(“%d”,&marks);

if (marks >= 30)
{

printf(” Student is pass\n”);

}
else
{

printf(” Student is fail\n”);

}
return 0;

}

Case 1:  Suppose you enter 20 means if condition is false, then this compiler execute else part only, the output will be:-
$  ./a.out
$   Enter the marks
$   Student is fail

Case 2 :  Suppose you enter 50 means if condition is true,  then compiler execute if part only, the output will be:-
$  ./a.out
$   Enter the marks
$   Student is pass

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.