if else statements in c
If is a conditional statement , with which you may take one or more test conditions. There are 3 types
- If statement
- If-else statement
- If else-if ladder
- nested if-else
1.if statement
only if statement has only one condition ,if the condition fails it skips to next statement.
syntax:
flowchart:

2.If-else Statement
if -else is used for both true and false for a condition.
syntax:
flowchart:

here, if the condition is true it executers statement1 and skips statement2.if the condition is false it executes statement2 and skips satement1. using else part is not mandatory,lets see one example
here, in this example ,the condition is ,the age of the person should be either 18 or more to enter the website. That means if the test expression given (a>=18) is true,it displays first message”you are allowed to enter this website” ,it it is false ,then the second message is displayed “you are not allowed to enter this website”.
3. If else-if ladder Statement
if else-if statement is used to work on multiple conditions .if the respective conditions are true then their statements are executed ,if they are false it skips to next condition
syntax:
4.nested if-else
writing if-else in another if-else is called nested if-else
until the condition 1 is true condition2 executes again and again ,when it is false else will be executed
example:
output: