Conditional Statements
Conditional Statements
GONDITIONAL STATEMENTS
C
IN C PROGRAM
◤
~ Thanishka Reddy
(24N81A6653)
~ Krishika Reddy
(24N81A6656)
~ Hansika (24N81A6670)
~ Hasini Reddy (24N81A6674)
◤
WHAT ARE CONDITIONAL
STATEMENTS ?
•the statements such as if, if else , Switch
etc are used for decision making purpose
in c program.
•They are also known as Decision-
Making Statements.
•They are used to evaluate one or
more conditions.
◤
Importance of conditional
statements
• Conditional statements are very much important in c
program.
• They help in decision making.
• Execute set of statements.
• Decide the direction of flow of program execution.
• Conditional statements enable a program to execute
different blocks of code based on the evaluation of specific
conditions.
• They make programs more flexible and versatile by
allowing them to respond to user inputs, external data, or
real-time events.
◤
Types of conditional
statements
• There are 5 types of conditional
statements :
• If Statement
• If-else statement
• Else if statement
• Nested if statement
• Switch Statement
◤
If Statement in c
•This “if” statements is the most simple
decision making statements .
•It is used to decide whether a certain
conditional statement should be executed
or not .
• SYNTAX:
• If (condition)
•{
• Set of statements;
•}
◤
If-else statement in c
• If statement tells about execution of a true
statement .
• But what if the condition is false?
• Here comes else statements
•Else is used With if condition if the statement
given is false
• SYNTAX:
• If (condition)
•{
• Set of statements;
•}
• Else
•{
• Set of statements;
•}
◤ Else if statement in c
•else if is used , when the user has to decide Among the
multiple options.
• The c if statements are executed from top to bottom.
• If else ladder is passed.
• Else will be executed at end.
• SYNTAX:
• If (condition)
• { statem
ent;
}
• else
if(conditi
on)
{
• stateme
nt
}
• else{
• stat
Nested if else statement in c
◤
•Nested if in c is an statement that is the target of
another if statement.
• it means one if statement Inside another if
statement.
• C allows Placing one if statement in Another if
statement.
• SYNTAX:
• if(condition)
•{
• If(condition)
• { statements;}
• Else
• { statements;}
•}
• Else
•{
• if(condition)
• {Statements;}
• Else
•
◤ Switch statement in c
• switch case statement is an alternative to the
if else ladder .
• It consists of cases that to be executed based
on the value of the switch variable.
• SYNTAX:
• Switch(expression)
•{
• Case value 1:statement;
• Break;
• Case value 2:statement;
• Break:
• Default:
•}
Examples
◤
• #include<stdio.h>
• int main()
•{
• int n;
• printf(“enter any value “);
• scanf(“%d”,&n);
• If(n>0)
• {
• printf(“you entered positive
number”);
• }
• printf(“ The End”);
• return0;
•}
◤
#include<stdio
.h> Int main()
{
Int age;
Printf(“enter
age:”);
Scanf(“%d”,&ag
e); If(age>=18)
{
Printf(“you are
eligilbke for
voting”);
}
Else
{
Printf(“ sorry
you are not
eligible for
voting”);
◤
Conclusion
•By this we can conclude that conditional
statements are very useful in C programming.
• They helps in decision making.
• Directs the flow of program execution.
◤
THANK
YOU