SlideShare una empresa de Scribd logo
1 de 22
Arun .R. Menon
arunrmenon555@gmail.com
www.facebook.com/arunrmenon
twitter.com/iamarunmenon
in.linkedin.com/in/mearunmenon
+919846629020
Control Structures in C
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
Control Structures
• System working
• Why control structures ?
• What is control Structures?
Styles of Control Structures in C
• Branching
• Looping
Branching
• What is Branching ?
• if statements
• ? : Operator
• switch statement
if statements
• If
• if (expression)
statement;
or
• if (expression)
{
Block of statements;
}
• If ……..else
if (expression)
{ Block of statements; }
else
{ Block of statements; }
• else if
if (expression)
{ Block of statements; }
else if(expression)
{ Block of statements; }
#include <stdio.h>
main() {
int cows = 6;
if (cows > 1)
printf("We have cowsn");
if (cows > 10)
printf("loads of them!n");
else
printf("Executing else part...!n");
if (cows == 5 )
{
printf("We have 5 cowsn");
}
else if( (cows == 6 )
{
printf("We have 6 cowsn");
}
We have cows
Executing else part...!
We have 6 cows
? : Operator
• Similar to if
• ternary operator
Eg
#include <stdio.h>
main()
{
int a , b;
a = 10;
printf( "Value of b is %dn", (a == 1) ? 20: 30 );
printf( "Value of b is %dn", (a == 10) ? 20: 30 );
}
Value of b is 30
Value of b is 20
switch statement
#include <stdio.h>
main()
{
int Grade = ‘ ’;
switch( Grade )
{
case 'A' : printf( "Excellentn" ); break;
case 'B' : printf( "Goodn" ); break;
case 'C' : printf( "OKn" ); break;
case 'D' : printf( "Mmmmm....n" ); break;
case 'F' : printf( "You must do better than thisn" ); 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
Looping
• What is looping
• for
• while
• dowhile
for loop
#include <stdio.h>
main()
{
int i;
for( i = 0; i <= j; i ++ )
{
printf("Hello %dn", i );
if( i == 6 )
{ break; }
}
}
Hello 0
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
Hello 6
while
#include <stdio.h>
main()
{
int i = 0;
while ( i < 5 )
{
if(i==4)
continue;
printf("Hello %dn", i );
i = i -1;
}
}
Hello 0
Hello 1
Hello 2
Hello 5
do while
#include <stdio.h>
main()
{
int i = 10;
do{
printf("Hello %dn", i );
i = i -1;
if( i == 6 ) { break; }
}
while ( i > 0 );
}
Hello 10
Hello 9
Hello 8
Hello 7
Hello 6
#include <stdio.h>
main()
{
int i = 1;
do{
printf("Hello %dn", i );
i = i -1;
if( i == 6 ) { break; }
}
while ( i > 5 );
}
Hello 1
THANK YOU
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 designed
to make a quick, good software professional out of anybody who holds a passion for coding.
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
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
Contact Us
Control structures in c
Control structures in c

Más contenido relacionado

Similar a Control structures in c

Similar a Control structures in c (20)

1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c program
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
 
Session05 iteration structure
Session05 iteration structureSession05 iteration structure
Session05 iteration structure
 
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
 
SPL 8 | Loop Statements in C
SPL 8 | Loop Statements in CSPL 8 | Loop Statements in C
SPL 8 | Loop Statements in C
 
Pi j1.4 loops
Pi j1.4 loopsPi j1.4 loops
Pi j1.4 loops
 
Looping
LoopingLooping
Looping
 
C Language Lecture 7
C Language Lecture 7C Language Lecture 7
C Language Lecture 7
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops
 
Some stuff about C++ and development
Some stuff about C++ and developmentSome stuff about C++ and development
Some stuff about C++ and development
 
Salesforce apex hours : Introduction to external services
Salesforce apex hours : Introduction to external servicesSalesforce apex hours : Introduction to external services
Salesforce apex hours : Introduction to external services
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
 
Scope of variables
Scope of variablesScope of variables
Scope of variables
 
Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.com
 
02 Java Language And OOP PART II
02 Java Language And OOP PART II02 Java Language And OOP PART II
02 Java Language And OOP PART II
 
Control structure in c
Control structure in cControl structure in c
Control structure in c
 
DIG1108C Lesson3 Fall 2014
DIG1108C Lesson3 Fall 2014DIG1108C Lesson3 Fall 2014
DIG1108C Lesson3 Fall 2014
 
Lecture - 5 Control Statement
Lecture - 5 Control StatementLecture - 5 Control Statement
Lecture - 5 Control Statement
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
 
Intro to Selenium UI Tests with pytest & some useful pytest plugins
Intro to Selenium UI Tests with pytest & some useful pytest pluginsIntro to Selenium UI Tests with pytest & some useful pytest plugins
Intro to Selenium UI Tests with pytest & some useful pytest plugins
 

Más de baabtra.com - No. 1 supplier of quality freshers

Más de baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Último (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

Control structures in c

  • 1.
  • 3. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 4. Control Structures • System working • Why control structures ? • What is control Structures?
  • 5. Styles of Control Structures in C • Branching • Looping
  • 6. Branching • What is Branching ? • if statements • ? : Operator • switch statement
  • 7. if statements • If • if (expression) statement; or • if (expression) { Block of statements; }
  • 8. • If ……..else if (expression) { Block of statements; } else { Block of statements; } • else if if (expression) { Block of statements; } else if(expression) { Block of statements; }
  • 9. #include <stdio.h> main() { int cows = 6; if (cows > 1) printf("We have cowsn"); if (cows > 10) printf("loads of them!n"); else printf("Executing else part...!n"); if (cows == 5 ) { printf("We have 5 cowsn"); } else if( (cows == 6 ) { printf("We have 6 cowsn"); } We have cows Executing else part...! We have 6 cows
  • 10. ? : Operator • Similar to if • ternary operator Eg #include <stdio.h> main() { int a , b; a = 10; printf( "Value of b is %dn", (a == 1) ? 20: 30 ); printf( "Value of b is %dn", (a == 10) ? 20: 30 ); } Value of b is 30 Value of b is 20
  • 11. switch statement #include <stdio.h> main() { int Grade = ‘ ’; switch( Grade ) { case 'A' : printf( "Excellentn" ); break; case 'B' : printf( "Goodn" ); break; case 'C' : printf( "OKn" ); break; case 'D' : printf( "Mmmmm....n" ); break; case 'F' : printf( "You must do better than thisn" ); 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
  • 12. Looping • What is looping • for • while • dowhile
  • 13. for loop #include <stdio.h> main() { int i; for( i = 0; i <= j; i ++ ) { printf("Hello %dn", i ); if( i == 6 ) { break; } } } Hello 0 Hello 1 Hello 2 Hello 3 Hello 4 Hello 5 Hello 6
  • 14. while #include <stdio.h> main() { int i = 0; while ( i < 5 ) { if(i==4) continue; printf("Hello %dn", i ); i = i -1; } } Hello 0 Hello 1 Hello 2 Hello 5
  • 15. do while #include <stdio.h> main() { int i = 10; do{ printf("Hello %dn", i ); i = i -1; if( i == 6 ) { break; } } while ( i > 0 ); } Hello 10 Hello 9 Hello 8 Hello 7 Hello 6
  • 16. #include <stdio.h> main() { int i = 1; do{ printf("Hello %dn", i ); i = i -1; if( i == 6 ) { break; } } while ( i > 5 ); } Hello 1
  • 18. 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 designed to make a quick, good software professional out of anybody who holds a passion for coding.
  • 19. 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
  • 20. Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Cafit Square, Hilite Business Park, Near Pantheerankavu, Kozhikode Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com Contact Us