SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Similaire à Control structures in c

Similaire à 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
 

Plus de baabtra.com - No. 1 supplier of quality freshers

Plus 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
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

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