if and if else Statement
if and if else Statement
if(expression)
//code to be executed
}
Flowchart of if statement in C
Program:
#include<stdio.h>
Int main(){
Int number=0;
Printf(“Enter a number:”);
Scanf(“%d”,&number);
If(number%2==0){
Return 0;
if-else Statement
The if-else statement is a decision-making statement that is used to decide
whether the part of the code will be executed or not based on the specified
condition (test expression). If the given condition is true, then the code
inside the if block is executed, otherwise the code inside the else block is
executed.
Syntax of if-else
if (condition) {
// code executed when the condition is true
}
else {
// code executed when the condition is false
}
#include<stdio.h>
Int main(){
Int number=0;
Printf(“enter a number:”);
Scanf(“%d”,&number);
If(number%2==0){
Else{
Return 0;