SlideShare uma empresa Scribd logo
1 de 21
ReshmaRaju
chippykutty5593@gmail.com
Reshmachippykutty
twitter.com/username
in.linkedin.com/in/profilename
8547829221
CONTROLSTRUCTUREIN 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 STRUCTURE IN C
 The control structure is any mechanism that departs from the
default straight-line execution.
 The instructions, statements or group of statements in a
programming language which determines the sequence of
execution of other instructions or statements.
if statement
 The if statement is a decision making statement.
 It is used to control the flow of execution and also used to
test logically whether the condition is true or false.
 Syntax:-
If(condition)
{
Statement;
}
Example for if statement
#include<stdio.h> OUTPUT
void main() Enter the number :9
{ The entered number 9 is less than 10
int i;
printf("Enter the number :");
scanf("%d",&i);
if(i<10)
{
printf("The entered number %d is less than 10",i);
}
}
If…..else statement
 The if....else statement is an extension of the simple if statement.
 The syntax is:
if (condition)
{
True-block statement;
}
else
{
False-block statement;
}
 If the condition is true, then the true-block statements are
executed; otherwise the false-block statement are executed.
Example for if….else statement
#include<stdio.h> OUTPUT
void main() Enter the number :50
{
int i; The entered number 50 is greater than 10
printf("Enter the number :");
scanf("%d",&i);
if(i<10)
{
printf(“nThe entered number %d is less than 10n",i);
}
else
{
printf(“nThe entered number %d is greater than 10n",i);
}
}
Nested If-else statement
 The nested if...else statement is used when program requires more than one
test expression.
 The syntax is:
if (test expression1)
{ statement to be executed if test expression1 is true;
}
else if(test expression2)
{statement to be executed if test expression1 is false and 2 is true;
}
else if (test expression 3)
{ statement to be executed if text expression1 and 2 are false and 3 is true;
}
.
.
else
{ statements to be executed if all test expressions are false;
}
Example for Nested if-else statement
#include <stdio.h> OUTPUT
int main() Enter two integers :40 50
{ Result: 50>40
int numb1, numb2;
printf("Enter two integers :");
scanf("%d %d",&numb1,&numb2);
if(numb1==numb2) //checking whether two integers are equal.
printf("Result: %d = %d",numb1,numb2);
else
if(numb1>numb2) //checking whether numb1 is greater than numb2.
printf("Result: %d > %d",numb1,numb2);
else
printf("Result: %d > %d",numb2,numb1);
}
Switch statement
 The switch statement evaluates an expression, then attempts to
match the result to one of several possible cases.
 Each case contains a value and a list of statements
 Often a break statement is used as the last statement in each
case's statement list
 A break statement causes control to transfer to the end of the
switch statement
 If a break statement is not used, the flow of control will continue
into the next case
Example for switch statement
#include<stdio.h>
void main()
{
int int_i; // declare the variable int_i
printf("n 1.Play game n");
printf("n 2.Load game n");
printf("n 3.Play multiplayer n");
printf("n 4.Exit n");
printf("n ENTER YOUR CHOICE:");
scanf("n %d",&int_i); //store the integer variable
switch(int_i) // select the switch case statement
{
case 1:
printf("n WELCOME PLAYER");
break; // break the case 1
case 2:
printf("n WAIT WHILE THE GAME IS LOADING");
break;
case 3:
printf("n CONNECT YOUR PARTNERS") ; OUTPUT
break; 1. Play Game
case 4: 2. Load Game
exit(0); //exit the function 3. Play Multiplayer
4. Exit
default: ENTER YOUR CHOICE:2
printf("n INVALID") ;
break; WAIT WHILE THE GAME IS LOADING
}
}
Ternary condition
Syntax :
expression 1 ? expression 2 : expression 3
 expression1 is Condition
 expression2 is Statement Followed if Condition is True
 expression2 is Statement Followed if Condition is False
Example for ternary condition
#include<stdio.h>
int main()
{
int num;
printf("Enter the Number : ");
scanf("%d",&num);
(num%2==0)?printf("Even"):printf("Odd");
}
OUTPUT
Enter the number : 5
Odd
Break statement
 break statement is used to exit from a loop or a switch, control
passing to the first statement beyond the loop or a switch.
Example for break statement
#include<stdio.h>
void main()
{
int i; OUTPUT
for(i=0;i<=10;i++)
{ 0 1 2 3 4
if(i==5)
{
break;
}
printf(" %d",i);
}
}
Continue statement
 continue is similar to the break statement but it only works
within loops where its effect is to force an immediate jump to
the loop control statement.
Example for continue statement
#include<stdio.h>
void main()
{
int i; OUTPUT
for(i=0;i<10;i++)
{ 0 1 2 3 4 5 6 7 8 9
if(i==5)
{
continue;
}
printf(" %d",i);
}
}
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

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

10. switch case
10. switch case10. switch case
10. switch case
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Functions in c
Functions in cFunctions in c
Functions in c
 
String functions in C
String functions in CString functions in C
String functions in C
 
Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Conditional statement in c
Conditional statement in cConditional statement in c
Conditional statement in c
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Loops c++
Loops c++Loops c++
Loops c++
 
Looping Statements and Control Statements in Python
Looping Statements and Control Statements in PythonLooping Statements and Control Statements in Python
Looping Statements and Control Statements in Python
 
Loops in c++ programming language
Loops in c++ programming language Loops in c++ programming language
Loops in c++ programming language
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 
Control structure in c
Control structure in cControl structure in c
Control structure in c
 

Destaque

C Prog. - ASCII Values, Break, Continue
C Prog. -  ASCII Values, Break, ContinueC Prog. -  ASCII Values, Break, Continue
C Prog. - ASCII Values, Break, Continue
vinay arora
 
Control Structures
Control StructuresControl Structures
Control Structures
Ghaffar Khan
 
Control structures in Java
Control structures in JavaControl structures in Java
Control structures in Java
Ravi_Kant_Sahu
 

Destaque (12)

Looping in C
Looping in CLooping in C
Looping in C
 
Loops in c
Loops in cLoops in c
Loops in c
 
C Programming (break and continue) - Coders Trust
C Programming (break and continue) -  Coders TrustC Programming (break and continue) -  Coders Trust
C Programming (break and continue) - Coders Trust
 
Control Structure in C
Control Structure in CControl Structure in C
Control Structure in C
 
Break and continue
Break and continueBreak and continue
Break and continue
 
Break and continue statement in C
Break and continue statement in CBreak and continue statement in C
Break and continue statement in C
 
C Prog. - ASCII Values, Break, Continue
C Prog. -  ASCII Values, Break, ContinueC Prog. -  ASCII Values, Break, Continue
C Prog. - ASCII Values, Break, Continue
 
Control Structures
Control StructuresControl Structures
Control Structures
 
Embedded c
Embedded cEmbedded c
Embedded c
 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C Programming
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
Control structures in Java
Control structures in JavaControl structures in Java
Control structures in Java
 

Semelhante a Control structures in c

Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
alish sha
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
alish sha
 

Semelhante a Control structures in c (20)

Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptx
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programming
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
if,loop,switch
if,loop,switchif,loop,switch
if,loop,switch
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 Slides
 
Elements of c program....by thanveer danish
Elements of c program....by thanveer danishElements of c program....by thanveer danish
Elements of c program....by thanveer danish
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Bsit1
Bsit1Bsit1
Bsit1
 
Control statement-Selective
Control statement-SelectiveControl statement-Selective
Control statement-Selective
 
Control structuresin c
Control structuresin cControl structuresin c
Control structuresin c
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptx
 

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

Mais 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
 

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 STRUCTURE IN C  The control structure is any mechanism that departs from the default straight-line execution.  The instructions, statements or group of statements in a programming language which determines the sequence of execution of other instructions or statements.
  • 5. if statement  The if statement is a decision making statement.  It is used to control the flow of execution and also used to test logically whether the condition is true or false.  Syntax:- If(condition) { Statement; }
  • 6. Example for if statement #include<stdio.h> OUTPUT void main() Enter the number :9 { The entered number 9 is less than 10 int i; printf("Enter the number :"); scanf("%d",&i); if(i<10) { printf("The entered number %d is less than 10",i); } }
  • 7. If…..else statement  The if....else statement is an extension of the simple if statement.  The syntax is: if (condition) { True-block statement; } else { False-block statement; }  If the condition is true, then the true-block statements are executed; otherwise the false-block statement are executed.
  • 8. Example for if….else statement #include<stdio.h> OUTPUT void main() Enter the number :50 { int i; The entered number 50 is greater than 10 printf("Enter the number :"); scanf("%d",&i); if(i<10) { printf(“nThe entered number %d is less than 10n",i); } else { printf(“nThe entered number %d is greater than 10n",i); } }
  • 9. Nested If-else statement  The nested if...else statement is used when program requires more than one test expression.  The syntax is: if (test expression1) { statement to be executed if test expression1 is true; } else if(test expression2) {statement to be executed if test expression1 is false and 2 is true; } else if (test expression 3) { statement to be executed if text expression1 and 2 are false and 3 is true; } . . else { statements to be executed if all test expressions are false; }
  • 10. Example for Nested if-else statement #include <stdio.h> OUTPUT int main() Enter two integers :40 50 { Result: 50>40 int numb1, numb2; printf("Enter two integers :"); scanf("%d %d",&numb1,&numb2); if(numb1==numb2) //checking whether two integers are equal. printf("Result: %d = %d",numb1,numb2); else if(numb1>numb2) //checking whether numb1 is greater than numb2. printf("Result: %d > %d",numb1,numb2); else printf("Result: %d > %d",numb2,numb1); }
  • 11. Switch statement  The switch statement evaluates an expression, then attempts to match the result to one of several possible cases.  Each case contains a value and a list of statements  Often a break statement is used as the last statement in each case's statement list  A break statement causes control to transfer to the end of the switch statement  If a break statement is not used, the flow of control will continue into the next case
  • 12. Example for switch statement #include<stdio.h> void main() { int int_i; // declare the variable int_i printf("n 1.Play game n"); printf("n 2.Load game n"); printf("n 3.Play multiplayer n"); printf("n 4.Exit n"); printf("n ENTER YOUR CHOICE:"); scanf("n %d",&int_i); //store the integer variable switch(int_i) // select the switch case statement { case 1: printf("n WELCOME PLAYER"); break; // break the case 1
  • 13. case 2: printf("n WAIT WHILE THE GAME IS LOADING"); break; case 3: printf("n CONNECT YOUR PARTNERS") ; OUTPUT break; 1. Play Game case 4: 2. Load Game exit(0); //exit the function 3. Play Multiplayer 4. Exit default: ENTER YOUR CHOICE:2 printf("n INVALID") ; break; WAIT WHILE THE GAME IS LOADING } }
  • 14. Ternary condition Syntax : expression 1 ? expression 2 : expression 3  expression1 is Condition  expression2 is Statement Followed if Condition is True  expression2 is Statement Followed if Condition is False
  • 15. Example for ternary condition #include<stdio.h> int main() { int num; printf("Enter the Number : "); scanf("%d",&num); (num%2==0)?printf("Even"):printf("Odd"); } OUTPUT Enter the number : 5 Odd
  • 16. Break statement  break statement is used to exit from a loop or a switch, control passing to the first statement beyond the loop or a switch. Example for break statement #include<stdio.h> void main() { int i; OUTPUT for(i=0;i<=10;i++) { 0 1 2 3 4 if(i==5) { break; } printf(" %d",i); } }
  • 17. Continue statement  continue is similar to the break statement but it only works within loops where its effect is to force an immediate jump to the loop control statement. Example for continue statement #include<stdio.h> void main() { int i; OUTPUT for(i=0;i<10;i++) { 0 1 2 3 4 5 6 7 8 9 if(i==5) { continue; } printf(" %d",i); } }
  • 19. 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.
  • 20. 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
  • 21. 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