0% found this document useful (0 votes)
3 views

if and if else Statement

The document explains the if and if-else statements in C programming, which are used for decision-making based on specified conditions. It provides the syntax for both statements and includes example programs demonstrating their usage to determine if a number is even or odd. Flowcharts for both statements are also mentioned to illustrate their logic.

Uploaded by

Jagmeet Maan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

if and if else Statement

The document explains the if and if-else statements in C programming, which are used for decision-making based on specified conditions. It provides the syntax for both statements and includes example programs demonstrating their usage to determine if a number is even or odd. Flowcharts for both statements are also mentioned to illustrate their logic.

Uploaded by

Jagmeet Maan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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;

You might also like