Conditional Control Statements
Conditional Control Statements
in a c language
statement inside {
If (condition)
another if statement
…….
is called nested if True block statements 1;
statement. }
……..
}
Else
{
False block statement 1;
}
Flow chart nested if:
Nested if statement program:
#include<stdio.h> Printf(“\n the number is less than 5 \
Void main() n”);
{ }
int n; }
Clrscr(); Else
Printf(“enter the value for n:”); {
Scanf(“%d”,&n); printf(“\n The number is entered is
If(n>5) less than zero \n”);
{ }
if(n>5) Printf(“\n End of the program”);
{ Getch();
Printf(“\n The number is greater }
than 5 \n”); Output:
} enter the value of n: 9
Else The number is greater than 5
{ End of the program
If-else-if statement(if-else ladder):
Writing a if Syntax:
if(condition1)
statement inside
{
else of an if
……
statement is called true block of statements 1;
if-else-if statement. …….
}
Else if(condition2)
{
false block of condition1;
&
true block of condition2;
}
Flowchart of if else ladder
If else ladder program
#include<stdio.h> Printf(“n is less than zero”);
Void main()
{
}
int n; getch();
Clrscr(); }
Printf(“enter the value of n:”);
Output:
Scanf(“%d”, &n);
If(n>0) enter the value of n:2
{ Given number is positive
printf(“given number is positive number
number”)
} //if its false
”) Else if(n<0) Enter the value of n:-3
{ Given number is negative
Printf(“given number is negative
number);
number
What we have learnt
Conditonal control staements
Simple if
If-else
Nested if
Else if ladder
The end
Thank you for giving this
opportunity