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

if and if else statement

The document explains the 'if statement' in C language, which is a decision-making structure used to execute statements based on a condition. It includes syntax for single and compound statements, along with examples and flowcharts. Additionally, it covers the 'if else statement' that executes one block of code if the condition is true and another if false, also providing a program example for determining if a number is even or odd.

Uploaded by

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

if and if else statement

The document explains the 'if statement' in C language, which is a decision-making structure used to execute statements based on a condition. It includes syntax for single and compound statements, along with examples and flowcharts. Additionally, it covers the 'if else statement' that executes one block of code if the condition is true and another if false, also providing a program example for determining if a number is even or odd.

Uploaded by

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

“if statement”

if is a keyword in c language.if statement is a decision making


statement. It is a simplest form of selection structure.It is used
to execute or skip statement or set of statements by checking
condition.
The condition is given as relational expression.If the condition is
true,then the statement or set of staements after if statement
is executed.If the condition is false,then the statement or set of
statement after if statement is not executed.
Syntax/general form:
The syntax of if statement is as follow:
if(condition)
Statement;
The above syntax is used for single statement. A set of
statements can also be make conditional.In this case, these
satements are written in curly brackets{ }. The set of statement
is also called conditional statement.
Flowchart:
The flowchart of if statement is as follows:
conditi
on statement

The syntax for compound statement in if statements is as


follows:
If (condition)
{
Statement1;
Statement2;
.
.
StatementN;
Program:
Write a program that input marks and display
“congratulation! You have passed”.If marks are 40 or
more.
#include<stdio.h>
#include<conoi.h>
Void main( )
{
int marks;
clrscr( );
printf(“enter your marks:”);
scanf(“%d”,&marks);
if(marks>=40)
printf(“congratulation! You have passed”);
getch( );
}
Output:
Enter your marks:60
congratulation!you have passed.

“if else statement”


if else statement is another form of if statement.It execute
one block of statement(s) when the condition is true and other
when it is false.In any situation one block is executed and other
is skipped.In if else statement :
 Both blocks of statements can never be executed.
 Both block of statements can never be skipped.
Syntax:
if(condition)
statement;
else
statement;
Two or more statements are written in curly brackets{ }.The
syntax for compound statement in if else statement is as
follows:
If(condition)
{
Statement1;
Statement2;
.
.
StatementN;
}
else
{
Statement1;
Statement2;
.
.
StatementN;
}
Flowchart:

conditi Statement
on (s)

Statement(s)

Program:
Write a program that input a number and find whether it is
even or odd using if else statement.
#include<stdio.h>
#include<conoi.h>
void main( )
{
int n;
clrscr( );
printf(“enter a number:”);
scanf(“%d”,&n”);
if(n%2==0)
printf(“number is even”);
else
printf(“number is odd”);
getch( );
}
Output:
enter a number:10
Number is even.

You might also like