SlideShare a Scribd company logo
1 of 28
Download to read offline
CHAPTER 11: Decision Constructs
COMPUTER SCIENCE
12
(MS Access and C)
Copyright @ IT Series www.itseries.com.pk
• Control Structure
• if Statement
• if-else Statement
• if-else-if Statement
• Nested if Statement
• Switch Statement
• Difference between if-else-if and switch Statement
• Conditional Operator
Topics
Copyright @ IT Series www.itseries.com.pk
possible to perform mathematical operation on character values
 Control structures control the flow of execution in a program
 The control structures in C language are used to combine individual instruction into a single logical unit
 The logical unit has one entry point and one exit point
 There are three kinds of execution flow:
• Sequence
• Selection
• Repetition
Copyright © IT Series
possible to perform mathematical operation on character values
Sequence
 Executes the statements in the same order in which they are written in the program
Entry point
Exit point
Flowchart
Copyright @ IT Series www.itseries.com.pk
possible to perform mathematical operation on character values
Selection
 A control structure which chooses alternative to execute
 Executes a statement or set of statements based on a condition
 Also called decision-making structure or conditional structure.
 Different types of selection structures in C language:
 If
 if-else
 if-else-if
 switch
Entry point
Exit point
Flowchart
Copyright @ IT Series www.itseries.com.pk
possible to perform mathematical operation on character values
Repetition
 A control structure which executes a statement or set of statements repeatedly for a specific number of times
 Also called iteration structure or loop
 Different types of loops available in C language:
 while loop
 do-while loop
 for loop
Entry point
Exit point
Flowchart
Copyright @ IT Series www.itseries.com.pk
possible to perform mathematical operation on character values
 The if statement is the primary selection control structure
 It is used to execute or skip a statement or set of statements by checking a condition
 The condition is given as a relational expression. e. g marks >=40
Syntax / General Form
The syntax of if statement for single statement:
if (condition)
statement;
The syntax for compound statements:
if (condition)
{
statement 1;
statement 2;

statement N;
}
if is a keyword in C
language. It is always
written in lowercase.
Block of statements
inside the braces is
called the body of the if
statement. If there is
only 1 statement in the
body, the { } may be
omitted.
Do not place ; after (condition)
Copyright @ IT Series www.itseries.com.pk
Copyright @ IT Series www.itseries.com.pk
possible to perform mathematical operation on character values
If Programs
Copyright @ IT Series www.itseries.com.pk
Copyright @ IT Series www.itseries.com.pk
possible to perform mathematical operation on character values
Copyright © IT Series
possible to perform mathematical operation on character values
 The simplest selection structure but it is very limited in its use
 Statement or set of statements is executed if the condition is true
 But if the condition is false then nothing happens (no alternate action is performed)
 A user may want to:
Execute one statement or set of statements if the condition is true
Execute other statement or set of statements if the condition is false
 In this situation, simple if statement cannot be used effectively
 Solution  ‘if-else’ structure can be used to handle this kind of situation effectively
Example
A program should display Pass! if the student gets 40 or more marks
It should display Fail! if the student gets less than 40 marks
Simple if statement cannot be used to handle this situation
Copyright @ IT Series www.itseries.com.pk
possible to perform mathematical operation on character values
 Used to make two-way decisions
 It executes one block of statement(s) when the condition is true and the other when it is false
 In any situation, one block is executed and the other is skipped
 Both blocks of statement can never be executed
 Both blocks of statements can never be skipped
Syntax / General Form
The syntax of if-else statement for single and compound statements:
Condition
Statement
Copyright © IT Series
Copyright @ IT Series www.itseries.com.pk
possible to perform mathematical operation on character values
If-else Programs
Copyright © IT Series
Copyright @ IT Series www.itseries.com.pk
possible to perform mathematical operation on character values
Copyright © IT Series
possible to perform mathematical operation on character values
 It is used when there are many options and only one block of statements should be executed on the basis of
a condition
Working of if-else-if
 The condition 1 is evaluated and the first block of statements is executed if the condition 1 is true
 The condition 2 is evaluated if the condition 1 is false. The second block of statements is executed if the
condition 2 is true
 The block of statements after the last else is executed if all conditions are false
Copyright © IT Series
Copyright @ IT Series www.itseries.com.pk
possible to perform mathematical operation on character values
if-else-if Programs
Copyright © IT Series
possible to perform mathematical operation on character values
Copyright © IT Series
possible to perform mathematical operation on character values
Copyright © IT Series
possible to perform mathematical operation on character values
Copyright @ IT Series www.itseries.com.pk
possible to perform mathematical operation on character values
 An if statement within an if statement is called nested if statement
Syntax / General Form
Working of Nested if
 the condition of outer if is evaluated first. If it is true, the control enters the inner if block
 If the condition is false, the inner if is skipped and control directly moves to the else part of outer if
 If outer if is true, the control enters the inner if statement
 The inner if evaluated according to simple if statement
Copyright © IT Series
Copyright @ IT Series www.itseries.com.pk
possible to perform mathematical operation on character values
Nested if Programs
Copyright @ IT Series www.itseries.com.pk
possible to perform mathematical operation on character values
 Select one of several alternatives when selection is based on the value of a single variable or an expression
 In C, the value of this expression may be of type int or char
 The switch statement is a better way of writing a program when a series of if-else-if occurs
Syntax / General Form
Copyright @ IT Series www.itseries.com.pk
Rules of using switch case in C program
• The case label must integer or character
• Each case label must be unique
• A switch statement can have only one default label
• The default label can be used anywhere in switch statement
• The case label must end with colon. The default label is optional
Copyright @ IT Series www.itseries.com.pk
Copyright @ IT Series www.itseries.com.pk
possible to perform mathematical operation on character values
switch Programs
Copyright © IT Series
Copyright @ IT Series www.itseries.com.pk
possible to perform mathematical operation on character values
possible to perform mathematical operation on character values
Copyright @ IT Series www.itseries.com.pk
 Conditional operator is a decision-making or selection control structure
 It can be used in place of simple if-else structure
 It is also called ternary operator as it uses three operands
Syntax
(condition) ? true : false;
condition The condition is specified as relational or logical expression
true It is executed if expression evaluates to true
false It is executed if expression evaluates to false
Example
X = (A>50) ? 1 : 0;
The above statement can be written using if-else statement:
if (A>50)
X = 1;
else
X = 0;
Copyright @ IT Series www.itseries.com.pk
Copyright @ IT Series www.itseries.com.pk
possible to perform mathematical operation on character values
Conditional Operator Programs
Copyright © IT Series

More Related Content

Similar to Chap11 (ICS12).pdf

Chapter 4 flow control structures and arrays
Chapter 4 flow control structures and arraysChapter 4 flow control structures and arrays
Chapter 4 flow control structures and arrayssshhzap
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsTech
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJTANUJ ⠀
 
Control Structures
Control StructuresControl Structures
Control StructuresGhaffar Khan
 
C language control statements
C language  control statementsC language  control statements
C language control statementssuman Aggarwal
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 SlidesRakesh Roshan
 
Java input Scanner
Java input Scanner Java input Scanner
Java input Scanner Huda Alameen
 
Password protected diary
Password protected diaryPassword protected diary
Password protected diarySHARDA SHARAN
 
Switch case and looping statement
Switch case and looping statementSwitch case and looping statement
Switch case and looping statement_jenica
 
Android Application Development - Level 3
Android Application Development - Level 3Android Application Development - Level 3
Android Application Development - Level 3Isham Rashik
 
C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c languagechintupro9
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision ControlJayfee Ramos
 
Ap Power Point Chpt3 B
Ap Power Point Chpt3 BAp Power Point Chpt3 B
Ap Power Point Chpt3 Bdplunkett
 

Similar to Chap11 (ICS12).pdf (20)

Chapter 4 flow control structures and arrays
Chapter 4 flow control structures and arraysChapter 4 flow control structures and arrays
Chapter 4 flow control structures and arrays
 
slides03.ppt
slides03.pptslides03.ppt
slides03.ppt
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
Control Structures
Control StructuresControl Structures
Control Structures
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
C language control statements
C language  control statementsC language  control statements
C language control statements
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 Slides
 
Programming in c by pkv
Programming in c by pkvProgramming in c by pkv
Programming in c by pkv
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Programming-in-C
Programming-in-CProgramming-in-C
Programming-in-C
 
Java input Scanner
Java input Scanner Java input Scanner
Java input Scanner
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Password protected diary
Password protected diaryPassword protected diary
Password protected diary
 
Switch case and looping statement
Switch case and looping statementSwitch case and looping statement
Switch case and looping statement
 
Android Application Development - Level 3
Android Application Development - Level 3Android Application Development - Level 3
Android Application Development - Level 3
 
C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c language
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
 
Ap Power Point Chpt3 B
Ap Power Point Chpt3 BAp Power Point Chpt3 B
Ap Power Point Chpt3 B
 

Recently uploaded

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Recently uploaded (20)

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

Chap11 (ICS12).pdf

  • 1. CHAPTER 11: Decision Constructs COMPUTER SCIENCE 12 (MS Access and C) Copyright @ IT Series www.itseries.com.pk
  • 2. • Control Structure • if Statement • if-else Statement • if-else-if Statement • Nested if Statement • Switch Statement • Difference between if-else-if and switch Statement • Conditional Operator Topics Copyright @ IT Series www.itseries.com.pk
  • 3. possible to perform mathematical operation on character values  Control structures control the flow of execution in a program  The control structures in C language are used to combine individual instruction into a single logical unit  The logical unit has one entry point and one exit point  There are three kinds of execution flow: • Sequence • Selection • Repetition Copyright © IT Series
  • 4. possible to perform mathematical operation on character values Sequence  Executes the statements in the same order in which they are written in the program Entry point Exit point Flowchart Copyright @ IT Series www.itseries.com.pk
  • 5. possible to perform mathematical operation on character values Selection  A control structure which chooses alternative to execute  Executes a statement or set of statements based on a condition  Also called decision-making structure or conditional structure.  Different types of selection structures in C language:  If  if-else  if-else-if  switch Entry point Exit point Flowchart Copyright @ IT Series www.itseries.com.pk
  • 6. possible to perform mathematical operation on character values Repetition  A control structure which executes a statement or set of statements repeatedly for a specific number of times  Also called iteration structure or loop  Different types of loops available in C language:  while loop  do-while loop  for loop Entry point Exit point Flowchart Copyright @ IT Series www.itseries.com.pk
  • 7. possible to perform mathematical operation on character values  The if statement is the primary selection control structure  It is used to execute or skip a statement or set of statements by checking a condition  The condition is given as a relational expression. e. g marks >=40 Syntax / General Form The syntax of if statement for single statement: if (condition) statement; The syntax for compound statements: if (condition) { statement 1; statement 2;  statement N; } if is a keyword in C language. It is always written in lowercase. Block of statements inside the braces is called the body of the if statement. If there is only 1 statement in the body, the { } may be omitted. Do not place ; after (condition) Copyright @ IT Series www.itseries.com.pk
  • 8. Copyright @ IT Series www.itseries.com.pk possible to perform mathematical operation on character values If Programs Copyright @ IT Series www.itseries.com.pk
  • 9. Copyright @ IT Series www.itseries.com.pk possible to perform mathematical operation on character values Copyright © IT Series
  • 10. possible to perform mathematical operation on character values  The simplest selection structure but it is very limited in its use  Statement or set of statements is executed if the condition is true  But if the condition is false then nothing happens (no alternate action is performed)  A user may want to: Execute one statement or set of statements if the condition is true Execute other statement or set of statements if the condition is false  In this situation, simple if statement cannot be used effectively  Solution  ‘if-else’ structure can be used to handle this kind of situation effectively Example A program should display Pass! if the student gets 40 or more marks It should display Fail! if the student gets less than 40 marks Simple if statement cannot be used to handle this situation Copyright @ IT Series www.itseries.com.pk
  • 11. possible to perform mathematical operation on character values  Used to make two-way decisions  It executes one block of statement(s) when the condition is true and the other when it is false  In any situation, one block is executed and the other is skipped  Both blocks of statement can never be executed  Both blocks of statements can never be skipped Syntax / General Form The syntax of if-else statement for single and compound statements: Condition Statement Copyright © IT Series
  • 12. Copyright @ IT Series www.itseries.com.pk possible to perform mathematical operation on character values If-else Programs Copyright © IT Series
  • 13. Copyright @ IT Series www.itseries.com.pk possible to perform mathematical operation on character values Copyright © IT Series
  • 14. possible to perform mathematical operation on character values  It is used when there are many options and only one block of statements should be executed on the basis of a condition Working of if-else-if  The condition 1 is evaluated and the first block of statements is executed if the condition 1 is true  The condition 2 is evaluated if the condition 1 is false. The second block of statements is executed if the condition 2 is true  The block of statements after the last else is executed if all conditions are false Copyright © IT Series
  • 15. Copyright @ IT Series www.itseries.com.pk possible to perform mathematical operation on character values if-else-if Programs Copyright © IT Series
  • 16. possible to perform mathematical operation on character values Copyright © IT Series
  • 17. possible to perform mathematical operation on character values Copyright © IT Series
  • 18. possible to perform mathematical operation on character values Copyright @ IT Series www.itseries.com.pk
  • 19. possible to perform mathematical operation on character values  An if statement within an if statement is called nested if statement Syntax / General Form Working of Nested if  the condition of outer if is evaluated first. If it is true, the control enters the inner if block  If the condition is false, the inner if is skipped and control directly moves to the else part of outer if  If outer if is true, the control enters the inner if statement  The inner if evaluated according to simple if statement Copyright © IT Series
  • 20. Copyright @ IT Series www.itseries.com.pk possible to perform mathematical operation on character values Nested if Programs
  • 21. Copyright @ IT Series www.itseries.com.pk possible to perform mathematical operation on character values
  • 22.  Select one of several alternatives when selection is based on the value of a single variable or an expression  In C, the value of this expression may be of type int or char  The switch statement is a better way of writing a program when a series of if-else-if occurs Syntax / General Form Copyright @ IT Series www.itseries.com.pk
  • 23. Rules of using switch case in C program • The case label must integer or character • Each case label must be unique • A switch statement can have only one default label • The default label can be used anywhere in switch statement • The case label must end with colon. The default label is optional Copyright @ IT Series www.itseries.com.pk
  • 24. Copyright @ IT Series www.itseries.com.pk possible to perform mathematical operation on character values switch Programs Copyright © IT Series
  • 25. Copyright @ IT Series www.itseries.com.pk possible to perform mathematical operation on character values
  • 26. possible to perform mathematical operation on character values Copyright @ IT Series www.itseries.com.pk
  • 27.  Conditional operator is a decision-making or selection control structure  It can be used in place of simple if-else structure  It is also called ternary operator as it uses three operands Syntax (condition) ? true : false; condition The condition is specified as relational or logical expression true It is executed if expression evaluates to true false It is executed if expression evaluates to false Example X = (A>50) ? 1 : 0; The above statement can be written using if-else statement: if (A>50) X = 1; else X = 0; Copyright @ IT Series www.itseries.com.pk
  • 28. Copyright @ IT Series www.itseries.com.pk possible to perform mathematical operation on character values Conditional Operator Programs Copyright © IT Series