- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Explain if-else statement in C language
If-else statement takes care of true as well as false conditions. ‘true block’ is executed, when the condition is true and ‘false block’ (or) ‘else block’ is executed, when the condition is false.
Syntax
Refer the syntax given below −
if (condition){ True block statement(s) }else{ False block statement(s) }
Working of ifelse statement
In if else condition, if condition is true, it enter into true block statements, execute the operation and exits from the block.
If condition is false, it enter into else block, which is false block based on if condition, executes that else block and exist that else block.
Example
Following is the C program to execute If and If Else conditional operators −
#include<stdio.h> void main (){ int a=4; printf("Enter the value of a:
"); scanf("%d",&a); if(a%2==1){ printf("a is odd number
"); }else{ printf("a is even number"); } }
Output
You will see the following output −
Run 1: Enter the value of a: 26 a is even number Run 2: Enter the value of a: 53 a is odd number
Advertisements