if Statement
The if statement in C is used to execute a block of code based on a specified
condition. It is the most simple decision-making statement. It consists of the
test condition and if block or body. If the given condition is true only then the if
block will be executed.
code to be executed if the condition is true
}
The syntax of the if statement in C is:
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){
Printf(“%d is even number”,number);
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
}
Flowchart of the if-else statement in C
Program
#include<stdio.h>
Int main(){
Int number=0;
Printf(“enter a number:”);
Scanf(“%d”,&number);
If(number%2==0){
Printf(“%d is even number”,number);
Else{
Printf(“%d is odd number”,number);
Return 0;