SlideShare uma empresa Scribd logo
1 de 22
Lecture 4Lecture 4
Version 1.0Version 1.0
AlgorithmAlgorithm
PseudocodePseudocode
The if StructureThe if Structure
The if/else StructureThe if/else Structure
The if/else if/else StructureThe if/else if/else Structure
Increment/Decrement OperatorsIncrement/Decrement Operators
2Rushdi Shams, Dept of CSE, KUET, Bangladesh
AlgorithmAlgorithm
 The solution of any computing problemThe solution of any computing problem
involves a series of action in a specific order.involves a series of action in a specific order.
 This procedure of solving problems is calledThis procedure of solving problems is called
algorithm.algorithm.
3Rushdi Shams, Dept of CSE, KUET, Bangladesh
AlgorithmAlgorithm
 What are the procedures you follow before youWhat are the procedures you follow before you
come to the class?come to the class?
4Rushdi Shams, Dept of CSE, KUET, Bangladesh
PseudocodePseudocode
 Pseudocode is an outline of aPseudocode is an outline of a programprogram, written, written
in a form that can easily be converted into realin a form that can easily be converted into real
programmingprogramming statementsstatements
 Pseudocode cannot bePseudocode cannot be compiledcompiled nornor executedexecuted,,
and there are no real formatting or syntax rulesand there are no real formatting or syntax rules
 It is simply one step - an important one - inIt is simply one step - an important one - in
producing the finalproducing the final codecode
5Rushdi Shams, Dept of CSE, KUET, Bangladesh
PseudocodePseudocode
 The benefit of pseudocode is that it enables theThe benefit of pseudocode is that it enables the
programmerprogrammer to concentrate on theto concentrate on the algorithmsalgorithms
without worrying about all the syntactic detailswithout worrying about all the syntactic details
of a particularof a particular programming languageprogramming language
 You can write pseudocode without evenYou can write pseudocode without even
knowing what programming language you willknowing what programming language you will
use for the final implementationuse for the final implementation
6Rushdi Shams, Dept of CSE, KUET, Bangladesh
The if Selection StructureThe if Selection Structure
 A selection structure is used to choose amongA selection structure is used to choose among
alternative courses of actionalternative courses of action
ifif student’s grade is more than 40student’s grade is more than 40
printprint “passed”“passed”
next pseudocode statementnext pseudocode statement
 In this pseudocode, if grade of a student is more thanIn this pseudocode, if grade of a student is more than
40 then the40 then the print commandprint command will be executed. Otherwise, ifwill be executed. Otherwise, if
the student’s grade is not more than 40, the compilerthe student’s grade is not more than 40, the compiler
will move towill move to next pseudocode statementnext pseudocode statement
7Rushdi Shams, Dept of CSE, KUET, Bangladesh
The if Selection StructureThe if Selection Structure
 So, as a general form, we can see the if selectionSo, as a general form, we can see the if selection
structure as-structure as-
if (condition){if (condition){
body of ifbody of if
}}
 TheThe conditioncondition needs to be true to get into theneeds to be true to get into the bodybody
of ifof if. Otherwise, the compiler will go to the next. Otherwise, the compiler will go to the next
segment of codessegment of codes
8Rushdi Shams, Dept of CSE, KUET, Bangladesh
The if Selection StructureThe if Selection Structure
 The pseudocode can be written in C as-The pseudocode can be written in C as-
if (grade>40)if (grade>40)
printf (“Passed n”);printf (“Passed n”);
9Rushdi Shams, Dept of CSE, KUET, Bangladesh
The if/else Selection StructureThe if/else Selection Structure
 The if/else structure allows the programmer to specifyThe if/else structure allows the programmer to specify
that different actions are to be performed when thethat different actions are to be performed when the
condition is true and when the condition is falsecondition is true and when the condition is false
ifif student’s grade is more than 40student’s grade is more than 40
printprint “passed”“passed”
elseelse
printprint “failed”“failed”
 If theIf the conditioncondition of if is true, then compiler will printof if is true, then compiler will print
passed and if thepassed and if the conditioncondition of if is false, the compiler willof if is false, the compiler will
print failed.print failed.
10Rushdi Shams, Dept of CSE, KUET, Bangladesh
The if/else Selection StructureThe if/else Selection Structure
 So, as a general form, we can see the if/elseSo, as a general form, we can see the if/else
selection structure as-selection structure as-
if (condition){if (condition){
body of ifbody of if
}}
else{else{
body of elsebody of else
}}
11Rushdi Shams, Dept of CSE, KUET, Bangladesh
The if/else Selection StructureThe if/else Selection Structure
 The pseudocode can be written in C as-The pseudocode can be written in C as-
if (grade>40)if (grade>40)
printf (“Passed n”);printf (“Passed n”);
elseelse
printf (“Failed n”);printf (“Failed n”);
12Rushdi Shams, Dept of CSE, KUET, Bangladesh
The if/else Selection StructureThe if/else Selection Structure
 An if structure may not have any else statementAn if structure may not have any else statement
followed by it but an else structure must have afollowed by it but an else structure must have a
if structure preceded.if structure preceded.
13Rushdi Shams, Dept of CSE, KUET, Bangladesh
The if/else if/else SelectionThe if/else if/else Selection
StructureStructure
 Now, consider a big scenario where you mayNow, consider a big scenario where you may
require a nested if else structure.require a nested if else structure.
14Rushdi Shams, Dept of CSE, KUET, Bangladesh
The if/else if/else SelectionThe if/else if/else Selection
StructureStructure
ifif student’s grade is more than 90student’s grade is more than 90
printprint “Grade: A”“Grade: A”
elseelse
ifif student’s grade is more than 80student’s grade is more than 80
printprint “Grade: B”“Grade: B”
elseelse
ifif student’s grade is more than 70student’s grade is more than 70
printprint “Grade: C”“Grade: C”
elseelse
ifif student’s grade is more than 60student’s grade is more than 60
printprint “Grade: D”“Grade: D”
elseelse
ifif student’s grade is more than 50student’s grade is more than 50
printprint “Grade: E”“Grade: E”
elseelse
printprint “Grade: F”“Grade: F”
15Rushdi Shams, Dept of CSE, KUET, Bangladesh
The if/else if/else SelectionThe if/else if/else Selection
StructureStructure
#include<stdio.h>#include<stdio.h>
#include<conio.h>#include<conio.h>
void main(){void main(){
clrscr();clrscr();
int grade;int grade;
printf("Enter your grade: ");printf("Enter your grade: ");
scanf("%d",&grade);scanf("%d",&grade);
if (grade>90)if (grade>90)
printf("Grade: A");printf("Grade: A");
else if (grade>80)else if (grade>80)
printf("Grade: B");printf("Grade: B");
else if (grade>70)else if (grade>70)
printf("Grade: C");printf("Grade: C");
else if (grade>60)else if (grade>60)
printf("Grade: D");printf("Grade: D");
else if (grade>50)else if (grade>50)
printf("Grade: E");printf("Grade: E");
elseelse
printf("Grade: F");printf("Grade: F");
getch();getch();
}}
16Rushdi Shams, Dept of CSE, KUET, Bangladesh
The if/else if/else SelectionThe if/else if/else Selection
StructureStructure
 Now, guess what happens if we replace theNow, guess what happens if we replace the
above code as follows-above code as follows-
17Rushdi Shams, Dept of CSE, KUET, Bangladesh
The if/else if/else SelectionThe if/else if/else Selection
StructureStructure
#include<stdio.h>#include<stdio.h>
#include<conio.h>#include<conio.h>
void main(){void main(){
clrscr();clrscr();
int grade;int grade;
printf("Enter your grade: ");printf("Enter your grade: ");
scanf("%d",&grade);scanf("%d",&grade);
if (grade>90)if (grade>90)
printf("Grade: A");printf("Grade: A");
if (grade>80)if (grade>80)
printf("Grade: B");printf("Grade: B");
if (grade>70)if (grade>70)
printf("Grade: C");printf("Grade: C");
if (grade>60)if (grade>60)
printf("Grade: D");printf("Grade: D");
if (grade>50)if (grade>50)
printf("Grade: E");printf("Grade: E");
elseelse
printf("Grade: F");printf("Grade: F");
getch();getch();
}}
18Rushdi Shams, Dept of CSE, KUET, Bangladesh
The if/else if/else SelectionThe if/else if/else Selection
StructureStructure
 This program will outputThis program will output Grade: C Grade: DGrade: C Grade: D
Grade: EGrade: E- this is not desirable- this is not desirable
19Rushdi Shams, Dept of CSE, KUET, Bangladesh
Increment and Decrement OperatorsIncrement and Decrement Operators
 C provides the unary increment operator ++C provides the unary increment operator ++
and unary decrement operator –and unary decrement operator –
 If a variable a is incremented by 1, the incrementIf a variable a is incremented by 1, the increment
operator ++ can be used instead of expressionoperator ++ can be used instead of expression
a=a+1a=a+1
 But the meaning differs based on the place ofBut the meaning differs based on the place of
the operator to the variablethe operator to the variable
20Rushdi Shams, Dept of CSE, KUET, Bangladesh
Increment and Decrement OperatorsIncrement and Decrement Operators
21Rushdi Shams, Dept of CSE, KUET, Bangladesh
Increment and Decrement OperatorsIncrement and Decrement Operators
 If unary increment/ decrement operators are placed inIf unary increment/ decrement operators are placed in
front of the variable, they are called preincrement/front of the variable, they are called preincrement/
predecrement operators otherwise they are calledpredecrement operators otherwise they are called
postincrement/ postdecrement operators.postincrement/ postdecrement operators.
22Rushdi Shams, Dept of CSE, KUET, Bangladesh
Increment and Decrement OperatorsIncrement and Decrement Operators

Mais conteúdo relacionado

Semelhante a Lec 04. If-Else Statement / Increment and Decrement Operators

Lec 03. Arithmetic Operator / Relational Operator
Lec 03. Arithmetic Operator / Relational OperatorLec 03. Arithmetic Operator / Relational Operator
Lec 03. Arithmetic Operator / Relational OperatorRushdi Shams
 
Lec 05. While Loop
Lec 05. While LoopLec 05. While Loop
Lec 05. While LoopRushdi Shams
 
[ITP - Lecture 08] Decision Control Structures (If Statement)
[ITP - Lecture 08] Decision Control Structures (If Statement)[ITP - Lecture 08] Decision Control Structures (If Statement)
[ITP - Lecture 08] Decision Control Structures (If Statement)Muhammad Hammad Waseem
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions imtiazalijoono
 
Conditional Statement
Conditional Statement Conditional Statement
Conditional Statement OXUS 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 arrayssshhzap
 
Fcp chapter 2 upto_if_else (2)
Fcp chapter 2 upto_if_else (2)Fcp chapter 2 upto_if_else (2)
Fcp chapter 2 upto_if_else (2)Jagdish Kamble
 
7 programming-using-java decision-making220102011
7 programming-using-java decision-making2201020117 programming-using-java decision-making220102011
7 programming-using-java decision-making220102011Mahmoud Alfarra
 
programming c language.
programming c language. programming c language.
programming c language. Abdul Rehman
 
Lec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by ValuesLec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by ValuesRushdi Shams
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docxJavvajiVenkat
 
Programming Basics if then else, switch, operators
Programming Basics if then else, switch, operatorsProgramming Basics if then else, switch, operators
Programming Basics if then else, switch, operatorsTrivuz ত্রিভুজ
 
#OOP_D_ITS - 3rd - Migration From C To C++
#OOP_D_ITS - 3rd - Migration From C To C++#OOP_D_ITS - 3rd - Migration From C To C++
#OOP_D_ITS - 3rd - Migration From C To C++Hadziq Fabroyir
 

Semelhante a Lec 04. If-Else Statement / Increment and Decrement Operators (20)

Lec 03. Arithmetic Operator / Relational Operator
Lec 03. Arithmetic Operator / Relational OperatorLec 03. Arithmetic Operator / Relational Operator
Lec 03. Arithmetic Operator / Relational Operator
 
Lec 05. While Loop
Lec 05. While LoopLec 05. While Loop
Lec 05. While Loop
 
jhtp9_ch04.ppt
jhtp9_ch04.pptjhtp9_ch04.ppt
jhtp9_ch04.ppt
 
[ITP - Lecture 08] Decision Control Structures (If Statement)
[ITP - Lecture 08] Decision Control Structures (If Statement)[ITP - Lecture 08] Decision Control Structures (If Statement)
[ITP - Lecture 08] Decision Control Structures (If Statement)
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions
 
control statement
control statement control statement
control statement
 
Conditional Statement
Conditional Statement Conditional Statement
Conditional Statement
 
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
 
03slide.ppt
03slide.ppt03slide.ppt
03slide.ppt
 
175035 cse lab-03
175035 cse lab-03175035 cse lab-03
175035 cse lab-03
 
Ch3.1
Ch3.1Ch3.1
Ch3.1
 
ICP - Lecture 7 and 8
ICP - Lecture 7 and 8ICP - Lecture 7 and 8
ICP - Lecture 7 and 8
 
Fcp chapter 2 upto_if_else (2)
Fcp chapter 2 upto_if_else (2)Fcp chapter 2 upto_if_else (2)
Fcp chapter 2 upto_if_else (2)
 
7 programming-using-java decision-making220102011
7 programming-using-java decision-making2201020117 programming-using-java decision-making220102011
7 programming-using-java decision-making220102011
 
programming c language.
programming c language. programming c language.
programming c language.
 
Lec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by ValuesLec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by Values
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
 
Programming Basics if then else, switch, operators
Programming Basics if then else, switch, operatorsProgramming Basics if then else, switch, operators
Programming Basics if then else, switch, operators
 
#OOP_D_ITS - 3rd - Migration From C To C++
#OOP_D_ITS - 3rd - Migration From C To C++#OOP_D_ITS - 3rd - Migration From C To C++
#OOP_D_ITS - 3rd - Migration From C To C++
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 

Mais de Rushdi Shams

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchRushdi Shams
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IRRushdi Shams
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101Rushdi Shams
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processingRushdi Shams
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: ParsingRushdi Shams
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translationRushdi Shams
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translationRushdi Shams
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semanticsRushdi Shams
 
Propositional logic
Propositional logicPropositional logic
Propositional logicRushdi Shams
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logicRushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structureRushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representationRushdi Shams
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hackingRushdi Shams
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)Rushdi Shams
 

Mais de Rushdi Shams (20)

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IR
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processing
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
 
L15 fuzzy logic
L15  fuzzy logicL15  fuzzy logic
L15 fuzzy logic
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
First order logic
First order logicFirst order logic
First order logic
 
Belief function
Belief functionBelief function
Belief function
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
 
L4 vpn
L4  vpnL4  vpn
L4 vpn
 
L3 defense
L3  defenseL3  defense
L3 defense
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
 
L1 phishing
L1  phishingL1  phishing
L1 phishing
 

Último

How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxPoojaSen20
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 

Último (20)

How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 

Lec 04. If-Else Statement / Increment and Decrement Operators

  • 1. Lecture 4Lecture 4 Version 1.0Version 1.0 AlgorithmAlgorithm PseudocodePseudocode The if StructureThe if Structure The if/else StructureThe if/else Structure The if/else if/else StructureThe if/else if/else Structure Increment/Decrement OperatorsIncrement/Decrement Operators
  • 2. 2Rushdi Shams, Dept of CSE, KUET, Bangladesh AlgorithmAlgorithm  The solution of any computing problemThe solution of any computing problem involves a series of action in a specific order.involves a series of action in a specific order.  This procedure of solving problems is calledThis procedure of solving problems is called algorithm.algorithm.
  • 3. 3Rushdi Shams, Dept of CSE, KUET, Bangladesh AlgorithmAlgorithm  What are the procedures you follow before youWhat are the procedures you follow before you come to the class?come to the class?
  • 4. 4Rushdi Shams, Dept of CSE, KUET, Bangladesh PseudocodePseudocode  Pseudocode is an outline of aPseudocode is an outline of a programprogram, written, written in a form that can easily be converted into realin a form that can easily be converted into real programmingprogramming statementsstatements  Pseudocode cannot bePseudocode cannot be compiledcompiled nornor executedexecuted,, and there are no real formatting or syntax rulesand there are no real formatting or syntax rules  It is simply one step - an important one - inIt is simply one step - an important one - in producing the finalproducing the final codecode
  • 5. 5Rushdi Shams, Dept of CSE, KUET, Bangladesh PseudocodePseudocode  The benefit of pseudocode is that it enables theThe benefit of pseudocode is that it enables the programmerprogrammer to concentrate on theto concentrate on the algorithmsalgorithms without worrying about all the syntactic detailswithout worrying about all the syntactic details of a particularof a particular programming languageprogramming language  You can write pseudocode without evenYou can write pseudocode without even knowing what programming language you willknowing what programming language you will use for the final implementationuse for the final implementation
  • 6. 6Rushdi Shams, Dept of CSE, KUET, Bangladesh The if Selection StructureThe if Selection Structure  A selection structure is used to choose amongA selection structure is used to choose among alternative courses of actionalternative courses of action ifif student’s grade is more than 40student’s grade is more than 40 printprint “passed”“passed” next pseudocode statementnext pseudocode statement  In this pseudocode, if grade of a student is more thanIn this pseudocode, if grade of a student is more than 40 then the40 then the print commandprint command will be executed. Otherwise, ifwill be executed. Otherwise, if the student’s grade is not more than 40, the compilerthe student’s grade is not more than 40, the compiler will move towill move to next pseudocode statementnext pseudocode statement
  • 7. 7Rushdi Shams, Dept of CSE, KUET, Bangladesh The if Selection StructureThe if Selection Structure  So, as a general form, we can see the if selectionSo, as a general form, we can see the if selection structure as-structure as- if (condition){if (condition){ body of ifbody of if }}  TheThe conditioncondition needs to be true to get into theneeds to be true to get into the bodybody of ifof if. Otherwise, the compiler will go to the next. Otherwise, the compiler will go to the next segment of codessegment of codes
  • 8. 8Rushdi Shams, Dept of CSE, KUET, Bangladesh The if Selection StructureThe if Selection Structure  The pseudocode can be written in C as-The pseudocode can be written in C as- if (grade>40)if (grade>40) printf (“Passed n”);printf (“Passed n”);
  • 9. 9Rushdi Shams, Dept of CSE, KUET, Bangladesh The if/else Selection StructureThe if/else Selection Structure  The if/else structure allows the programmer to specifyThe if/else structure allows the programmer to specify that different actions are to be performed when thethat different actions are to be performed when the condition is true and when the condition is falsecondition is true and when the condition is false ifif student’s grade is more than 40student’s grade is more than 40 printprint “passed”“passed” elseelse printprint “failed”“failed”  If theIf the conditioncondition of if is true, then compiler will printof if is true, then compiler will print passed and if thepassed and if the conditioncondition of if is false, the compiler willof if is false, the compiler will print failed.print failed.
  • 10. 10Rushdi Shams, Dept of CSE, KUET, Bangladesh The if/else Selection StructureThe if/else Selection Structure  So, as a general form, we can see the if/elseSo, as a general form, we can see the if/else selection structure as-selection structure as- if (condition){if (condition){ body of ifbody of if }} else{else{ body of elsebody of else }}
  • 11. 11Rushdi Shams, Dept of CSE, KUET, Bangladesh The if/else Selection StructureThe if/else Selection Structure  The pseudocode can be written in C as-The pseudocode can be written in C as- if (grade>40)if (grade>40) printf (“Passed n”);printf (“Passed n”); elseelse printf (“Failed n”);printf (“Failed n”);
  • 12. 12Rushdi Shams, Dept of CSE, KUET, Bangladesh The if/else Selection StructureThe if/else Selection Structure  An if structure may not have any else statementAn if structure may not have any else statement followed by it but an else structure must have afollowed by it but an else structure must have a if structure preceded.if structure preceded.
  • 13. 13Rushdi Shams, Dept of CSE, KUET, Bangladesh The if/else if/else SelectionThe if/else if/else Selection StructureStructure  Now, consider a big scenario where you mayNow, consider a big scenario where you may require a nested if else structure.require a nested if else structure.
  • 14. 14Rushdi Shams, Dept of CSE, KUET, Bangladesh The if/else if/else SelectionThe if/else if/else Selection StructureStructure ifif student’s grade is more than 90student’s grade is more than 90 printprint “Grade: A”“Grade: A” elseelse ifif student’s grade is more than 80student’s grade is more than 80 printprint “Grade: B”“Grade: B” elseelse ifif student’s grade is more than 70student’s grade is more than 70 printprint “Grade: C”“Grade: C” elseelse ifif student’s grade is more than 60student’s grade is more than 60 printprint “Grade: D”“Grade: D” elseelse ifif student’s grade is more than 50student’s grade is more than 50 printprint “Grade: E”“Grade: E” elseelse printprint “Grade: F”“Grade: F”
  • 15. 15Rushdi Shams, Dept of CSE, KUET, Bangladesh The if/else if/else SelectionThe if/else if/else Selection StructureStructure #include<stdio.h>#include<stdio.h> #include<conio.h>#include<conio.h> void main(){void main(){ clrscr();clrscr(); int grade;int grade; printf("Enter your grade: ");printf("Enter your grade: "); scanf("%d",&grade);scanf("%d",&grade); if (grade>90)if (grade>90) printf("Grade: A");printf("Grade: A"); else if (grade>80)else if (grade>80) printf("Grade: B");printf("Grade: B"); else if (grade>70)else if (grade>70) printf("Grade: C");printf("Grade: C"); else if (grade>60)else if (grade>60) printf("Grade: D");printf("Grade: D"); else if (grade>50)else if (grade>50) printf("Grade: E");printf("Grade: E"); elseelse printf("Grade: F");printf("Grade: F"); getch();getch(); }}
  • 16. 16Rushdi Shams, Dept of CSE, KUET, Bangladesh The if/else if/else SelectionThe if/else if/else Selection StructureStructure  Now, guess what happens if we replace theNow, guess what happens if we replace the above code as follows-above code as follows-
  • 17. 17Rushdi Shams, Dept of CSE, KUET, Bangladesh The if/else if/else SelectionThe if/else if/else Selection StructureStructure #include<stdio.h>#include<stdio.h> #include<conio.h>#include<conio.h> void main(){void main(){ clrscr();clrscr(); int grade;int grade; printf("Enter your grade: ");printf("Enter your grade: "); scanf("%d",&grade);scanf("%d",&grade); if (grade>90)if (grade>90) printf("Grade: A");printf("Grade: A"); if (grade>80)if (grade>80) printf("Grade: B");printf("Grade: B"); if (grade>70)if (grade>70) printf("Grade: C");printf("Grade: C"); if (grade>60)if (grade>60) printf("Grade: D");printf("Grade: D"); if (grade>50)if (grade>50) printf("Grade: E");printf("Grade: E"); elseelse printf("Grade: F");printf("Grade: F"); getch();getch(); }}
  • 18. 18Rushdi Shams, Dept of CSE, KUET, Bangladesh The if/else if/else SelectionThe if/else if/else Selection StructureStructure  This program will outputThis program will output Grade: C Grade: DGrade: C Grade: D Grade: EGrade: E- this is not desirable- this is not desirable
  • 19. 19Rushdi Shams, Dept of CSE, KUET, Bangladesh Increment and Decrement OperatorsIncrement and Decrement Operators  C provides the unary increment operator ++C provides the unary increment operator ++ and unary decrement operator –and unary decrement operator –  If a variable a is incremented by 1, the incrementIf a variable a is incremented by 1, the increment operator ++ can be used instead of expressionoperator ++ can be used instead of expression a=a+1a=a+1  But the meaning differs based on the place ofBut the meaning differs based on the place of the operator to the variablethe operator to the variable
  • 20. 20Rushdi Shams, Dept of CSE, KUET, Bangladesh Increment and Decrement OperatorsIncrement and Decrement Operators
  • 21. 21Rushdi Shams, Dept of CSE, KUET, Bangladesh Increment and Decrement OperatorsIncrement and Decrement Operators  If unary increment/ decrement operators are placed inIf unary increment/ decrement operators are placed in front of the variable, they are called preincrement/front of the variable, they are called preincrement/ predecrement operators otherwise they are calledpredecrement operators otherwise they are called postincrement/ postdecrement operators.postincrement/ postdecrement operators.
  • 22. 22Rushdi Shams, Dept of CSE, KUET, Bangladesh Increment and Decrement OperatorsIncrement and Decrement Operators