ifelse statement in C

The ifelse statement is used in those conditions where two possibilities are there either true or false. The if statement states that if a condition is true then it will execute a block of statements and if the condition is false, it will not execute. The else statement can be used when the condition is false.

The basic format of ifelse statement.

if(test_expression)
{
// execute your code
}
else
{
// execute your code
}




Flowchart of ifelse statement.

start
expression false
true
statements in if branch statements in else branch
stop

The basic example of C Program for ifelse statement.

#include<stdio.h>
main()
{
int a,b;
printf("Please enter the value for x:");
scanf("%d", & amp; x);
printf("\nPlease enter the value for y:");
scanf("%d", & amp; y);
if (x & gt; y) {
     printf("\n x is greater");
} else {
   printf("\n b is greater");
  }
}

Coding Tag

Coding Tag always happy to serve you in Information Technology (IT). Learn HTML, CSS, Javascript, PHP, Android, Digital Marketing, Latest IT News and many more.

Leave a Reply

avatar
  Subscribe  
Notify of