Control structure
-
Upload
baabtracom-no-1-supplier-of-quality-freshers -
Category
Documents
-
view
164 -
download
0
Transcript of Control structure
![Page 1: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/1.jpg)
![Page 2: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/2.jpg)
Fasil KM
www.facebook.com/Fasil faas
twitter.com/fasilemv
in.linkedin.com/in/fasilemv
+919544334000
Control Structures in C
![Page 3: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/3.jpg)
Disclaimer: This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
![Page 4: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/4.jpg)
Control Structures
• System working
• Why control structures ?
• What is control Structures?
![Page 5: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/5.jpg)
Styles of Control Structures in C
• Branching
• Looping
![Page 6: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/6.jpg)
Branching
• What is Branching ?
• if statements
• ? : Operator
• switch statement
![Page 7: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/7.jpg)
if statements
• If
• if (expression)
statement;
or
• if (expression)
{
Block of statements;
}
![Page 8: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/8.jpg)
• If ……..else
if (expression)
{ Block of statements; }
else
{ Block of statements; }
• else if
if (expression)
{ Block of statements; }
else if(expression)
{ Block of statements; }
![Page 9: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/9.jpg)
#include <stdio.h>
main() {
int cows = 6;
if (cows > 1)
printf("We have cows\n");
if (cows > 10)
printf("loads of them!\n");
else
printf("Executing else part...!\n");
if (cows == 5 )
{
printf("We have 5 cows\n");
}
else if( (cows == 6 )
{
printf("We have 6 cows\n");
}
We have cows
Executing else part...!
We have 6 cows
![Page 10: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/10.jpg)
? : Operator
• Similar to if
• ternary operatorEg
#include <stdio.h>
main()
{
int a , b;
a = 10;
printf( "Value of b is %d\n", (a == 1) ? 20: 30 );
printf( "Value of b is %d\n", (a == 10) ? 20: 30 );
}
Value of b is 30
Value of b is 20
![Page 11: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/11.jpg)
switch statement#include <stdio.h>
main()
{
int Grade = ‘ ’;
switch( Grade )
{
case 'A' : printf( "Excellent\n" ); break;
case 'B' : printf( "Good\n" ); break;
case 'C' : printf( "OK\n" ); break;
case 'D' : printf( "Mmmmm....\n" ); break;
case 'F' : printf( "You must do better than this\n" ); break;
default : printf( "What is your grade anyway?\n" ); break;
}
}
A
Excellent
B C D F def
Good
Ok
Mmmm
You must do ..
What is your
![Page 12: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/12.jpg)
Looping
• What is looping
• for
• while
• dowhile
![Page 13: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/13.jpg)
for loop
#include <stdio.h>
main()
{
int i;
for( i = 0; i <= j; i ++ )
{
printf("Hello %d\n", i );
if( i == 6 )
{ break; }
}
}
Hello 0
Hello 1Hello 2Hello 3Hello 4Hello 5Hello 6
![Page 14: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/14.jpg)
while
#include <stdio.h>
main()
{
int i = 0;
while ( i < 5 )
{
if(i==4)
continue;
printf("Hello %d\n", i );
i = i -1;
}
}
Hello 0
Hello 1Hello 2
Hello 5
![Page 15: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/15.jpg)
do while#include <stdio.h>
main()
{
int i = 10;
do{
printf("Hello %d\n", i );
i = i -1;
if( i == 6 ) { break; }
}
while ( i > 0 );
}
Hello 10
Hello 9Hello 8
Hello 7
Hello 6
![Page 16: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/16.jpg)
#include <stdio.h>
main()
{
int i = 1;
do{
printf("Hello %d\n", i );
i = i -1;
if( i == 6 ) { break; }
}
while ( i > 5 );
}
Hello 1
![Page 17: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/17.jpg)
THANK YOU
![Page 18: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/18.jpg)
Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many contents online?
Do you want to learn things quickly?
Tired of spending huge amount of money to become a Software professional?
Do an online course @ baabtra.com
We put industry standards to practice. Our structured, activity based courses are so designedto make a quick, good software professional out of anybody who holds a passion for coding.
![Page 19: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/19.jpg)
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advance
www.baabtra.com | www.massbaab.com |www.baabte.com
![Page 20: Control structure](https://reader034.fdocuments.us/reader034/viewer/2022052700/55a242e11a28abfc448b466d/html5/thumbnails/20.jpg)
Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
Cafit Square,Hilite Business Park,Near Pantheerankavu,Kozhikode
Start up VillageEranakulam,Kerala, India.
Email: [email protected]
Contact Us