The document discusses various control structures in the C language including conditional statements like if, if-else-if and switch statements, as well as loops and the goto statement. It provides examples of using if statements to check for even or odd numbers, if-else-if to check positive, negative and zero numbers, and switch statements to check the modulus of a number. The break and goto statements are also explained briefly.
Control Structures inC Language
Typing Speed:19
Fasalul habeeb
fasalulhabeeb@gmail.com
www.facebook.com/Fasalul
habeeb
twitter.com/username
in.linkedin.com/in/profilenam
e
9544962714
3.
Control Structures inC Language
• C language possesses such decision making
capabilities and supports the following
statements known as control or decisionmaking statements.
• if statement
switch statement
Conditional operator statement
goto statements
4.
if Statement
• Theif statement is a powerful decision making statement and
is used to controlthe flow of execution of statements. It is
basically a two-way decision statement and is used in
conjunction with an expression.
Syntax
if (conditional)
{
block of statements executed if conditional is true;
}
else
{
block of statements if condition false;
}
if-else-if statement
•
void main(void)
{
intnumb;
printf("Type any Number : ");
scanf("%d", &numb);
if(numb > 0) {
printf("%d is the positive number", numb);
}
else if(numb < 0)
printf("%d is the Negative number", numb);
else printf("%d is zero",numb);
}
7.
Switch Statement:
•
The switchand case statements help control
complex conditional and branching
operations.
The switch statement transfers control to a
statement within its body.
8.
Example of aswitch statement
• #include
main(){
int numb;
printf("Type any Number");
scanf("%d",&numb);
switch(numb %2)
{
case 0 : printf("the number %d is even ", numb);
}
}
case 1 : printf("the number %d is odd ", numb);
break;
9.
break statement
•
•
•
break statementis used to exit from a loop or a switch, control passing to the first
statement beyond the loop or a switch.
Example
for(i=0;i<=10;i++)
{
if(i==5)
{
break;
}
printf(" %d",i);
}
Output:
0
1
2
3
4
10.
The goto statement
•The goto is a unconditional branching statement
used to transfer control of the program from
one statement to another.
• syntax
• goto label;
• .............
• .............
• label:
• statement;
If this presentationhelped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
13.
Contact Us
Emarald Mall(Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550