SlideShare a Scribd company logo
ALGORITHMS AND
FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
 A typical programming task can be divided into
two phases:
 Problem solving phase
 produce an ordered sequence of steps that describe
solution of problem
 this sequence of steps is called an algorithm
 Implementation phase
 implement the program in some programming
language
Steps in Problem Solving
 First produce a general algorithm (one can use
pseudocode)
 Refine the algorithm successively to get step by
step detailed algorithm that is very close to a
computer language.
 Pseudocode is an artificial and informal
language that helps programmers develop
algorithms. Pseudocode is very similar to
everyday English.
Pseudocode & Algorithm
 Example 1: Write an algorithm to
determine a student’s final grade and
indicate whether it is passing or failing.
The final grade is calculated as the
average of four marks.
Pseudocode & Algorithm
Pseudocode:
 Input a set of 4 marks
 Calculate their average by summing and dividing
by 4
 if average is below 50
Print “FAIL”
else
Print “PASS”
Pseudocode & Algorithm
 Detailed Algorithm
 Step 1: Input M1,M2,M3,M4
Step 2: GRADE  (M1+M2+M3+M4)/4
Step 3: if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
endif
The Flowchart
 (Dictionary) A schematic representation of a sequence of
operations, as in a manufacturing process or computer
program.
 (Technical) A graphical representation of the sequence
of operations in an information system or program.
Information system flowcharts show how data flows from
source documents through the computer to final
distribution to users. Program flowcharts show the
sequence of instructions in a single program or
subroutine. Different symbols are used to draw each
type of flowchart.
The Flowchart
A Flowchart
shows logic of an algorithm
emphasizes individual steps and their
interconnections
e.g. control flow from one action to the next
Flowchart Symbols
Basic
Oval
Parallelogram
Rectangle
Diamond
Hybrid
Name Symbol Use in Flowchart
Denotes the beginning or end of the program
Denotes an input operation
Denotes an output operation
Denotes a decision (or branch) to be made.
The program should continue along one of
two routes. (e.g. IF/THEN/ELSE)
Denotes a process to be carried out
e.g. addition, subtraction, division etc.
Flow line Denotes the direction of logic flow in the program
Example
PRINT
“PASS”
Step 1: Input M1,M2,M3,M4
Step 2: GRADE  (M1+M2+M3+M4)/4
Step 3: if (GRADE <50) then
Print “FAIL”
else
Print “PASS”
endif
START
Input
M1,M2,M3,M4
GRADE(M1+M2+M3+M4)/4
IS
GRADE<5
0
PRINT
“FAIL”
STOP
Y
N
Example 2
 Write an algorithm and draw a flowchart to
convert the length in feet to centimeter.
Pseudocode:
 Input the length in feet (Lft)
 Calculate the length in cm (Lcm) by
multiplying LFT with 30
 Print length in cm (LCM)
Example 2
Algorithm
 Step 1: Input Lft
 Step 2: Lcm  Lft x 30
 Step 3: Print Lcm
START
Input
Lft
Lcm  Lft x 30
Print
Lcm
STOP
Flowchart
Example 3
Write an algorithm and draw a flowchart that
will read the two sides of a rectangle and
calculate its area.
Pseudocode
 Input the width (W) and Length (L) of a rectangle
 Calculate the area (A) by multiplying L with W
 Print A
Example 3
Algorithm
 Step 1: Input W,L
 Step 2: A  L x W
 Step 3: Print A
START
Input
W, L
A  L x W
Print
A
STOP
Example 4
 Write an algorithm and draw a flowchart that
will calculate the roots of a quadratic equation
 Hint: d = sqrt ( ), and the roots are:
x1 = (–b + d)/2a and x2 = (–b – d)/2a
2
0
ax bx c
  
2
4
b ac

Example 4
Pseudocode:
 Input the coefficients (a, b, c) of the
quadratic equation
 Calculate d
 Calculate x1
 Calculate x2
 Print x1 and x2
Example 4
 Algorithm:
 Step 1: Input a, b, c
 Step 2: d  sqrt ( )
 Step 3: x1  (–b + d) / (2 x a)
 Step 4: x2  (–b – d) / (2 x a)
 Step 5: Print x1, x2
START
Input
a, b, c
d  sqrt(b x b – 4 x a x c)
Print
x1 ,x2
STOP
x1 (–b + d) / (2 x a)
X2  (–b – d) / (2 x a)
4
b b a c
   
DECISION STRUCTURES
 The expression A>B is a logical expression
 it describes a condition we want to test
 if A>B is true (if A is greater than B) we take
the action on left
 print the value of A
 if A>B is false (if A is not greater than B) we
take the action on right
 print the value of B
DECISION STRUCTURES
is
A>B
Print
B
Print
A
Y N
IF–THEN–ELSE STRUCTURE
 The structure is as follows
If condition then
true alternative
else
false alternative
endif
IF–THEN–ELSE STRUCTURE
 The algorithm for the flowchart is as
follows:
If A>B then
print A
else
print B
endif
is
A>B
Print
B
Print
A
Y N
Relational Operators
Relational Operators
Operator Description
> Greater than
< Less than
= Equal to
 Greater than or equal to
 Less than or equal to
 Not equal to
Example 6
 Write an algorithm that reads two values, determines the
largest value and prints the largest value with an
identifying message.
ALGORITHM
Step 1: Input VALUE1, VALUE2
Step 2: if (VALUE1 > VALUE2) then
MAX  VALUE1
else
MAX  VALUE2
endif
Step 3: Print “The largest value is”, MAX
Example 6
MAX  VALUE1
Print
“The largest value is”,
MAX
STOP
Y N
START
Input
VALUE1,VALUE2
MAX  VALUE2
is
VALUE1>VALUE2
LOOPS
 Computers are particularly well suited to
applications in which operations are
repeated many times.
 If the same task is repeated over and over
again a loop can be used to reduce
program size and complexity
Example 7: Write an algorithm and
draw a flowchart to calculate 24 .
 Algorithm:
 Step 1: Base  2
 Step 2: Product  Base
 Step 3: Product  Product * Base
 Step 4: Product  Product * Base
 Step 5: Product  Product * Base
 Step 6: Print Product
Flowchart
START
Product  Base
Print
Product
STOP
Product  Product * Base
Product  Product * Base
Product  Product * Base
Base2
 Question: What happens if you want to
calculate 2 to the power of 1000?
 Answer: Use a LOOP (repeated execution
of the same set of instructions)
Example 8:
 Write an algorithm and draw a flowchart to
calculate 24 using a loop approach? Verify
your result by a trace table.
Algorithm:
Step 1: Base  2
Step 2: Power  4
Step 3: Product  Base
Step 4: Counter  1
Step 5: While Counter < Power
Repeat Step 5 through step 7
Step 6: Product  Product * Base
Step 7: Counter  Counter +1
Step 8: Print Product
START
Product  Base
Counter  1
Print
Product
STOP
Y
is
Counter < Power
Product  Product * Base
Counter  Counter + 1
N
Base  2
Power 4
TRACING
BASE POWER PRODUCT COUNTER COUNTER < POWER
STEP 1: 2 ? ? ? ?
STEP 2: 2 4 ? ? ?
STEP 3: 2 4 2 ? ?
STEP 4: 2 4 2 1 T
STEP 5: 2 4 2 1 T
STEP 6: 2 4 2x2=4 1 T
STEP 7: 2 4 4 1+1=2 T
STEP 5: 2 4 4 2 T
STEP 6: 2 4 4x2=8 2 T
STEP 7: 2 4 8 2+1=3 T
STEP 5: 2 4 8 3 T
STEP 6: 2 4 8x2=16 3 T
STEP 7: 2 4 16 3+1=4 F
STEP 5: 2 4 16 4 F
STEP 8: print 16.
Step 1: Base  2
Step 2: Power  4
Step 3: Product  Base
Step 4: Counter  1
Step 5: While Counter < Power
Repeat Step 5 through
step 7
Step 6: Product  Product *
Base
Step 7: Counter  Counter +1
Step 8: Print Product
 Example 10: Write down an algorithm and
draw a flowchart to find and print the
largest of three numbers. Read numbers
one by one. Verify your result by a trace
table. (Use 5, 7, 3 as the numbers read)
Algorithm
 Step 1: Input N1
 Step 2: Max  N1
 Step 3: Input N2
 Step 4: If (N2>Max) then
Max = N2
endif
 Step 5: Input N3
 Step 6: If (N3>Max) then
Max = N3
endif
 Step 7: Print “The largest number is:”,Max
Flowchart &
Tracing
START
INPUT
N1
MAXN1
INPUT
N2
N2>MAX
MAXN2
INPUT
N3
MAXN3
Print
“Largest
Number is”,
MAX
STOP
N3>MAX
N
Y
N
Y
N1 N2 N3 Max N2>Max N3>Max
Step1: 5 ? ? ? ? ?
Step 2: 5 ? ? 5 ? ?
Step 3: 5 7 ? 5 T ?
Step 4: 5 7 ? 7 T ?
Step 5: 5 7 3 7 F F
Step 6: 5 7 3 7 F F
Step 8: Print  Largest Number is 7
 Example 11: Write down an algorithm and
draw a flowchart to find and print the
largest of N (N can be any number)
numbers. Read numbers one by one.
Verify your result by a trace table.
(Assume N to be 5 and the following set to
be the numbers {1 4 2 6 8 })
Algorithm:
 Step 1: Input N
 Step 2: Input X
 Step 3: Max  Current
 Step 4: Counter 1
 Step 5: While (Counter < N)
Repeat steps 5 through 8
 Step 6: Counter  Counter + 1
 Step 7: Input X
 Step 8: If (X > Max) then
Max  X
endif
 Step 9: Print Max
N X Max Cou
nter
Count
er < N
Next >
Max
Step 1
Step 2
Step 3
Step 4
Step 5
Step 6
Step 7
Step 8
Step 5
Step 6
Step 7
Step 8
Step 5
Step 6
Step 7
Step 8
Step 5
Step 6
Step 7
Step 8
Step 5
Step 9
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
1
1
1
1
1
1
4
4
4
4
2
2
2
2
6
6
6
6
8
8
8
1
1
1
1
1
4
4
4
4
4
4
4
4
6
6
6
6
8
8
8
output
1
1
2
2
2
2
3
3
3
3
4
4
4
4
5
5
5
5
T
T
T
T
T
T
T
T
T
T
T
T
T
T
F
F
F
F
T
F
F
F
F
F
F
T
T
F
F
T
T
F
START
Input
N, X
Max  X
Print
Max
STOP
Y
Counter < N
N
Counter 1
Counter  Counter +1
Input
X
X>Max
Y
N
Max  X
1
2
3
4
5
6
7
8
9
Tracing
How many times will steps 4, 6, and 7 be executed?
Do Loops
 It is convenient to introduce a special type
of loop that is headed by a special
macroinstructions.
 This terminology comes from FORTRAN ,
although many programming languages
have this type of loop.
 For example :
BASIC
DO K=1 to N
{body of loop}
END;
 FORTRAN
Do n K=1 , N
{body of loop}
n CONTIOUE
ALGORITHMS AND FLOWCHARTS
 Example : A company has 80
employees give a flowchart that
 finds the average salary and the number
of employees earning above the average
salary. Observe that the salaries are read
into an array, SALARY. Next, the average
salary, AVG, is calculated.
 Then each salary , SALARY(K), is
compared with AVG to obtain the number
NUM of salaries grater than AVG.
ALGORITHMS AND FLOWCHARTS
PROBLEMS
 Prob. 1. Write an algorithm and draw a flowchart to
print the square of all numbers from 1 to10.
 Prob. 2. Write an algorithm and draw a flowchart to
print the SUM of numbers from LOW to HIGH. Test
with LOW=3 and HIGH=9.
 Prob. 3. Write an algorithm and draw a flowchart to
print all numbers between LOW and HIGH that are
divisible by NUMBER.
 Prob. 4. Draw a flowchart for a program that reads
10 numbers from the user and prints out their sum,
and their product.
 Prob. 5. Write an algorithm and draw a flowchart to
count and print all numbers from LOW to HIGH by
steps of STEP. Test with LOW=0 and HIGH=100 and
STEP=5.
 Prob. 6. Write an algorithm and draw a flowchart to
print the multiplication table for 6's. i.e.
---- 1  6 = 6
---- 2  6 = 12
…
---- 12  6 = 72
 Prob. 7. Write an algorithm and draw a flowchart that
will find and print the product of 3 numbers.

 Prob. 8. Write an algorithm and draw a
flowchart that will find and print
 The factorial of NUMBER is FACTORIAL.
 Test the flowchart for NUMBER=5.

More Related Content

What's hot (20)

Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
Sachin Goyani
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
Elizabeth de Leon Aler
 
Assembly language (addition and subtraction)
Assembly language (addition and subtraction)Assembly language (addition and subtraction)
Assembly language (addition and subtraction)
Muhammad Umar Farooq
 
Digital logic design part1
Digital logic design part1Digital logic design part1
Digital logic design part1
Vaagdevi College of Engineering
 
digital logic design number system
digital logic design number systemdigital logic design number system
digital logic design number system
Nallapati Anindra
 
Lecture Note-1: Algorithm and Its Properties
Lecture Note-1: Algorithm and Its PropertiesLecture Note-1: Algorithm and Its Properties
Lecture Note-1: Algorithm and Its Properties
Rajesh K Shukla
 
Modular programming
Modular programmingModular programming
Modular programming
Mohanlal Sukhadia University (MLSU)
 
Chapter 03 arithmetic for computers
Chapter 03   arithmetic for computersChapter 03   arithmetic for computers
Chapter 03 arithmetic for computers
Bảo Hoang
 
Problem solving (C++ Programming)
Problem solving (C++ Programming)Problem solving (C++ Programming)
Problem solving (C++ Programming)
Umair Younas
 
Heap sort
Heap sortHeap sort
Heap sort
Ayesha Tahir
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
Rabin BK
 
Huffman coding
Huffman coding Huffman coding
Huffman coding
Nazmul Hyder
 
assembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YUassembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YU
Education
 
Elements of dynamic programming
Elements of dynamic programmingElements of dynamic programming
Elements of dynamic programming
Tafhim Islam
 
Signed Addition And Subtraction
Signed Addition And SubtractionSigned Addition And Subtraction
Signed Addition And Subtraction
Keyur Vadodariya
 
Intro to assembly language
Intro to assembly languageIntro to assembly language
Intro to assembly language
United International University
 
Computer architecture addressing modes and formats
Computer architecture addressing modes and formatsComputer architecture addressing modes and formats
Computer architecture addressing modes and formats
Mazin Alwaaly
 
Division algorithm
Division algorithmDivision algorithm
Division algorithm
SnehalataAgasti
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
salmankhan570
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
Sachin Goyani
 
Assembly language (addition and subtraction)
Assembly language (addition and subtraction)Assembly language (addition and subtraction)
Assembly language (addition and subtraction)
Muhammad Umar Farooq
 
digital logic design number system
digital logic design number systemdigital logic design number system
digital logic design number system
Nallapati Anindra
 
Lecture Note-1: Algorithm and Its Properties
Lecture Note-1: Algorithm and Its PropertiesLecture Note-1: Algorithm and Its Properties
Lecture Note-1: Algorithm and Its Properties
Rajesh K Shukla
 
Chapter 03 arithmetic for computers
Chapter 03   arithmetic for computersChapter 03   arithmetic for computers
Chapter 03 arithmetic for computers
Bảo Hoang
 
Problem solving (C++ Programming)
Problem solving (C++ Programming)Problem solving (C++ Programming)
Problem solving (C++ Programming)
Umair Younas
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
Rabin BK
 
assembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YUassembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YU
Education
 
Elements of dynamic programming
Elements of dynamic programmingElements of dynamic programming
Elements of dynamic programming
Tafhim Islam
 
Signed Addition And Subtraction
Signed Addition And SubtractionSigned Addition And Subtraction
Signed Addition And Subtraction
Keyur Vadodariya
 
Computer architecture addressing modes and formats
Computer architecture addressing modes and formatsComputer architecture addressing modes and formats
Computer architecture addressing modes and formats
Mazin Alwaaly
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
salmankhan570
 

Similar to ALGORITHMS AND FLOWCHARTS (20)

Algorithms-Flowcharts for programming fundamental
Algorithms-Flowcharts for  programming fundamentalAlgorithms-Flowcharts for  programming fundamental
Algorithms-Flowcharts for programming fundamental
fazayn927
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
rajnidhiman
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
ወዲ ህዝቢ
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
Deva Singh
 
Algorithms and flowcharts ppt (seminar presentation)..
 Algorithms and flowcharts  ppt (seminar presentation).. Algorithms and flowcharts  ppt (seminar presentation)..
Algorithms and flowcharts ppt (seminar presentation)..
Nagendra N
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
Emmanuel Alimpolos
 
01 Algorithms And Flowcharts.ppt
01 Algorithms And Flowcharts.ppt01 Algorithms And Flowcharts.ppt
01 Algorithms And Flowcharts.ppt
FerdieBalang
 
Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowcharts
khair20
 
256958.ppt
256958.ppt256958.ppt
256958.ppt
Bimlesh7
 
Best Techniques To Design Programs - Program Designing Techniques
Best Techniques To Design Programs - Program Designing TechniquesBest Techniques To Design Programs - Program Designing Techniques
Best Techniques To Design Programs - Program Designing Techniques
Tech
 
Programming algorithms and flowchart.ppt
Programming algorithms and flowchart.pptProgramming algorithms and flowchart.ppt
Programming algorithms and flowchart.ppt
VictorMorcillo1
 
Flowchart and algorithm
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithm
DHANIK VIKRANT
 
Program design techniques
Program design techniquesProgram design techniques
Program design techniques
fika sweety
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
Rohit Shrivastava
 
Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowcharts
Samuel Igbanogu
 
Problem Solving - Introduction to Flowcharts.pptx
Problem Solving - Introduction to Flowcharts.pptxProblem Solving - Introduction to Flowcharts.pptx
Problem Solving - Introduction to Flowcharts.pptx
aroojtmalik
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
Jesuraj Love
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
luhkahreth
 
Algorithms and flowcharts1
Algorithms and flowcharts1Algorithms and flowcharts1
Algorithms and flowcharts1
Lincoln School
 
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.pptBCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
Kirti Verma
 
Algorithms-Flowcharts for programming fundamental
Algorithms-Flowcharts for  programming fundamentalAlgorithms-Flowcharts for  programming fundamental
Algorithms-Flowcharts for programming fundamental
fazayn927
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
rajnidhiman
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
Deva Singh
 
Algorithms and flowcharts ppt (seminar presentation)..
 Algorithms and flowcharts  ppt (seminar presentation).. Algorithms and flowcharts  ppt (seminar presentation)..
Algorithms and flowcharts ppt (seminar presentation)..
Nagendra N
 
01 Algorithms And Flowcharts.ppt
01 Algorithms And Flowcharts.ppt01 Algorithms And Flowcharts.ppt
01 Algorithms And Flowcharts.ppt
FerdieBalang
 
Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowcharts
khair20
 
256958.ppt
256958.ppt256958.ppt
256958.ppt
Bimlesh7
 
Best Techniques To Design Programs - Program Designing Techniques
Best Techniques To Design Programs - Program Designing TechniquesBest Techniques To Design Programs - Program Designing Techniques
Best Techniques To Design Programs - Program Designing Techniques
Tech
 
Programming algorithms and flowchart.ppt
Programming algorithms and flowchart.pptProgramming algorithms and flowchart.ppt
Programming algorithms and flowchart.ppt
VictorMorcillo1
 
Flowchart and algorithm
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithm
DHANIK VIKRANT
 
Program design techniques
Program design techniquesProgram design techniques
Program design techniques
fika sweety
 
Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowcharts
Samuel Igbanogu
 
Problem Solving - Introduction to Flowcharts.pptx
Problem Solving - Introduction to Flowcharts.pptxProblem Solving - Introduction to Flowcharts.pptx
Problem Solving - Introduction to Flowcharts.pptx
aroojtmalik
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
Jesuraj Love
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
luhkahreth
 
Algorithms and flowcharts1
Algorithms and flowcharts1Algorithms and flowcharts1
Algorithms and flowcharts1
Lincoln School
 
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.pptBCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
Kirti Verma
 
Ad

More from Kate Campbell (20)

Writing Creative Nonfiction By Philip Gerard, Paperbac
Writing Creative Nonfiction By Philip Gerard, PaperbacWriting Creative Nonfiction By Philip Gerard, Paperbac
Writing Creative Nonfiction By Philip Gerard, Paperbac
Kate Campbell
 
Free Lined Writing Paper Printable - Prin
Free Lined Writing Paper Printable - PrinFree Lined Writing Paper Printable - Prin
Free Lined Writing Paper Printable - Prin
Kate Campbell
 
How To Cite APA In Text Citation How To Use Apa Format For Citation
How To Cite APA In Text Citation How To Use Apa Format For CitationHow To Cite APA In Text Citation How To Use Apa Format For Citation
How To Cite APA In Text Citation How To Use Apa Format For Citation
Kate Campbell
 
Sea Turtle Writing Paper
Sea Turtle Writing PaperSea Turtle Writing Paper
Sea Turtle Writing Paper
Kate Campbell
 
Heart-Shaped Printable Writing Page Valentines
Heart-Shaped Printable Writing Page ValentinesHeart-Shaped Printable Writing Page Valentines
Heart-Shaped Printable Writing Page Valentines
Kate Campbell
 
High School Vs College
High School Vs CollegeHigh School Vs College
High School Vs College
Kate Campbell
 
College Essay On Leadership
College Essay On LeadershipCollege Essay On Leadership
College Essay On Leadership
Kate Campbell
 
Writing A Research Paper - A Step-By-Step Approach TeacherS Guide
Writing A Research Paper - A Step-By-Step Approach TeacherS GuideWriting A Research Paper - A Step-By-Step Approach TeacherS Guide
Writing A Research Paper - A Step-By-Step Approach TeacherS Guide
Kate Campbell
 
How To Write A Poem ChildrenS Book By Cecilia
How To Write A Poem ChildrenS Book By CeciliaHow To Write A Poem ChildrenS Book By Cecilia
How To Write A Poem ChildrenS Book By Cecilia
Kate Campbell
 
Easy Essay On Global Warming. G
Easy Essay On Global Warming. GEasy Essay On Global Warming. G
Easy Essay On Global Warming. G
Kate Campbell
 
Sample Conclusion Of A Research Paper What I
Sample Conclusion Of A Research Paper What ISample Conclusion Of A Research Paper What I
Sample Conclusion Of A Research Paper What I
Kate Campbell
 
Why I Wish To Attend Virginia Commonwealth University
Why I Wish To Attend Virginia Commonwealth UniversityWhy I Wish To Attend Virginia Commonwealth University
Why I Wish To Attend Virginia Commonwealth University
Kate Campbell
 
Essay On My Teacher Is The
Essay On My Teacher Is TheEssay On My Teacher Is The
Essay On My Teacher Is The
Kate Campbell
 
Chinese Character Practice Writing Paper
Chinese Character Practice Writing PaperChinese Character Practice Writing Paper
Chinese Character Practice Writing Paper
Kate Campbell
 
Hello Kitty Backgrounds, Hello Kitty Wallpaper, Sanr
Hello Kitty Backgrounds, Hello Kitty Wallpaper, SanrHello Kitty Backgrounds, Hello Kitty Wallpaper, Sanr
Hello Kitty Backgrounds, Hello Kitty Wallpaper, Sanr
Kate Campbell
 
The Best IELTS Task 2 Writing Template - Magoos
The Best IELTS Task 2 Writing Template - MagoosThe Best IELTS Task 2 Writing Template - Magoos
The Best IELTS Task 2 Writing Template - Magoos
Kate Campbell
 
Rhetorical Analysis Essay Conclusion. Rhetorical Anal
Rhetorical Analysis Essay Conclusion. Rhetorical AnalRhetorical Analysis Essay Conclusion. Rhetorical Anal
Rhetorical Analysis Essay Conclusion. Rhetorical Anal
Kate Campbell
 
Handwriting Without Tears Paper Handwriting Withou
Handwriting Without Tears Paper Handwriting WithouHandwriting Without Tears Paper Handwriting Withou
Handwriting Without Tears Paper Handwriting Withou
Kate Campbell
 
Sample For Report Writing
Sample For Report WritingSample For Report Writing
Sample For Report Writing
Kate Campbell
 
Expert MBA Essay Writing Service Essay Writing, Writing Services
Expert MBA Essay Writing Service Essay Writing, Writing ServicesExpert MBA Essay Writing Service Essay Writing, Writing Services
Expert MBA Essay Writing Service Essay Writing, Writing Services
Kate Campbell
 
Writing Creative Nonfiction By Philip Gerard, Paperbac
Writing Creative Nonfiction By Philip Gerard, PaperbacWriting Creative Nonfiction By Philip Gerard, Paperbac
Writing Creative Nonfiction By Philip Gerard, Paperbac
Kate Campbell
 
Free Lined Writing Paper Printable - Prin
Free Lined Writing Paper Printable - PrinFree Lined Writing Paper Printable - Prin
Free Lined Writing Paper Printable - Prin
Kate Campbell
 
How To Cite APA In Text Citation How To Use Apa Format For Citation
How To Cite APA In Text Citation How To Use Apa Format For CitationHow To Cite APA In Text Citation How To Use Apa Format For Citation
How To Cite APA In Text Citation How To Use Apa Format For Citation
Kate Campbell
 
Sea Turtle Writing Paper
Sea Turtle Writing PaperSea Turtle Writing Paper
Sea Turtle Writing Paper
Kate Campbell
 
Heart-Shaped Printable Writing Page Valentines
Heart-Shaped Printable Writing Page ValentinesHeart-Shaped Printable Writing Page Valentines
Heart-Shaped Printable Writing Page Valentines
Kate Campbell
 
High School Vs College
High School Vs CollegeHigh School Vs College
High School Vs College
Kate Campbell
 
College Essay On Leadership
College Essay On LeadershipCollege Essay On Leadership
College Essay On Leadership
Kate Campbell
 
Writing A Research Paper - A Step-By-Step Approach TeacherS Guide
Writing A Research Paper - A Step-By-Step Approach TeacherS GuideWriting A Research Paper - A Step-By-Step Approach TeacherS Guide
Writing A Research Paper - A Step-By-Step Approach TeacherS Guide
Kate Campbell
 
How To Write A Poem ChildrenS Book By Cecilia
How To Write A Poem ChildrenS Book By CeciliaHow To Write A Poem ChildrenS Book By Cecilia
How To Write A Poem ChildrenS Book By Cecilia
Kate Campbell
 
Easy Essay On Global Warming. G
Easy Essay On Global Warming. GEasy Essay On Global Warming. G
Easy Essay On Global Warming. G
Kate Campbell
 
Sample Conclusion Of A Research Paper What I
Sample Conclusion Of A Research Paper What ISample Conclusion Of A Research Paper What I
Sample Conclusion Of A Research Paper What I
Kate Campbell
 
Why I Wish To Attend Virginia Commonwealth University
Why I Wish To Attend Virginia Commonwealth UniversityWhy I Wish To Attend Virginia Commonwealth University
Why I Wish To Attend Virginia Commonwealth University
Kate Campbell
 
Essay On My Teacher Is The
Essay On My Teacher Is TheEssay On My Teacher Is The
Essay On My Teacher Is The
Kate Campbell
 
Chinese Character Practice Writing Paper
Chinese Character Practice Writing PaperChinese Character Practice Writing Paper
Chinese Character Practice Writing Paper
Kate Campbell
 
Hello Kitty Backgrounds, Hello Kitty Wallpaper, Sanr
Hello Kitty Backgrounds, Hello Kitty Wallpaper, SanrHello Kitty Backgrounds, Hello Kitty Wallpaper, Sanr
Hello Kitty Backgrounds, Hello Kitty Wallpaper, Sanr
Kate Campbell
 
The Best IELTS Task 2 Writing Template - Magoos
The Best IELTS Task 2 Writing Template - MagoosThe Best IELTS Task 2 Writing Template - Magoos
The Best IELTS Task 2 Writing Template - Magoos
Kate Campbell
 
Rhetorical Analysis Essay Conclusion. Rhetorical Anal
Rhetorical Analysis Essay Conclusion. Rhetorical AnalRhetorical Analysis Essay Conclusion. Rhetorical Anal
Rhetorical Analysis Essay Conclusion. Rhetorical Anal
Kate Campbell
 
Handwriting Without Tears Paper Handwriting Withou
Handwriting Without Tears Paper Handwriting WithouHandwriting Without Tears Paper Handwriting Withou
Handwriting Without Tears Paper Handwriting Withou
Kate Campbell
 
Sample For Report Writing
Sample For Report WritingSample For Report Writing
Sample For Report Writing
Kate Campbell
 
Expert MBA Essay Writing Service Essay Writing, Writing Services
Expert MBA Essay Writing Service Essay Writing, Writing ServicesExpert MBA Essay Writing Service Essay Writing, Writing Services
Expert MBA Essay Writing Service Essay Writing, Writing Services
Kate Campbell
 
Ad

Recently uploaded (20)

Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
National Information Standards Organization (NISO)
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 

ALGORITHMS AND FLOWCHARTS

  • 2. ALGORITHMS AND FLOWCHARTS  A typical programming task can be divided into two phases:  Problem solving phase  produce an ordered sequence of steps that describe solution of problem  this sequence of steps is called an algorithm  Implementation phase  implement the program in some programming language
  • 3. Steps in Problem Solving  First produce a general algorithm (one can use pseudocode)  Refine the algorithm successively to get step by step detailed algorithm that is very close to a computer language.  Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode is very similar to everyday English.
  • 4. Pseudocode & Algorithm  Example 1: Write an algorithm to determine a student’s final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks.
  • 5. Pseudocode & Algorithm Pseudocode:  Input a set of 4 marks  Calculate their average by summing and dividing by 4  if average is below 50 Print “FAIL” else Print “PASS”
  • 6. Pseudocode & Algorithm  Detailed Algorithm  Step 1: Input M1,M2,M3,M4 Step 2: GRADE  (M1+M2+M3+M4)/4 Step 3: if (GRADE < 50) then Print “FAIL” else Print “PASS” endif
  • 7. The Flowchart  (Dictionary) A schematic representation of a sequence of operations, as in a manufacturing process or computer program.  (Technical) A graphical representation of the sequence of operations in an information system or program. Information system flowcharts show how data flows from source documents through the computer to final distribution to users. Program flowcharts show the sequence of instructions in a single program or subroutine. Different symbols are used to draw each type of flowchart.
  • 8. The Flowchart A Flowchart shows logic of an algorithm emphasizes individual steps and their interconnections e.g. control flow from one action to the next
  • 9. Flowchart Symbols Basic Oval Parallelogram Rectangle Diamond Hybrid Name Symbol Use in Flowchart Denotes the beginning or end of the program Denotes an input operation Denotes an output operation Denotes a decision (or branch) to be made. The program should continue along one of two routes. (e.g. IF/THEN/ELSE) Denotes a process to be carried out e.g. addition, subtraction, division etc. Flow line Denotes the direction of logic flow in the program
  • 10. Example PRINT “PASS” Step 1: Input M1,M2,M3,M4 Step 2: GRADE  (M1+M2+M3+M4)/4 Step 3: if (GRADE <50) then Print “FAIL” else Print “PASS” endif START Input M1,M2,M3,M4 GRADE(M1+M2+M3+M4)/4 IS GRADE<5 0 PRINT “FAIL” STOP Y N
  • 11. Example 2  Write an algorithm and draw a flowchart to convert the length in feet to centimeter. Pseudocode:  Input the length in feet (Lft)  Calculate the length in cm (Lcm) by multiplying LFT with 30  Print length in cm (LCM)
  • 12. Example 2 Algorithm  Step 1: Input Lft  Step 2: Lcm  Lft x 30  Step 3: Print Lcm START Input Lft Lcm  Lft x 30 Print Lcm STOP Flowchart
  • 13. Example 3 Write an algorithm and draw a flowchart that will read the two sides of a rectangle and calculate its area. Pseudocode  Input the width (W) and Length (L) of a rectangle  Calculate the area (A) by multiplying L with W  Print A
  • 14. Example 3 Algorithm  Step 1: Input W,L  Step 2: A  L x W  Step 3: Print A START Input W, L A  L x W Print A STOP
  • 15. Example 4  Write an algorithm and draw a flowchart that will calculate the roots of a quadratic equation  Hint: d = sqrt ( ), and the roots are: x1 = (–b + d)/2a and x2 = (–b – d)/2a 2 0 ax bx c    2 4 b ac 
  • 16. Example 4 Pseudocode:  Input the coefficients (a, b, c) of the quadratic equation  Calculate d  Calculate x1  Calculate x2  Print x1 and x2
  • 17. Example 4  Algorithm:  Step 1: Input a, b, c  Step 2: d  sqrt ( )  Step 3: x1  (–b + d) / (2 x a)  Step 4: x2  (–b – d) / (2 x a)  Step 5: Print x1, x2 START Input a, b, c d  sqrt(b x b – 4 x a x c) Print x1 ,x2 STOP x1 (–b + d) / (2 x a) X2  (–b – d) / (2 x a) 4 b b a c    
  • 18. DECISION STRUCTURES  The expression A>B is a logical expression  it describes a condition we want to test  if A>B is true (if A is greater than B) we take the action on left  print the value of A  if A>B is false (if A is not greater than B) we take the action on right  print the value of B
  • 20. IF–THEN–ELSE STRUCTURE  The structure is as follows If condition then true alternative else false alternative endif
  • 21. IF–THEN–ELSE STRUCTURE  The algorithm for the flowchart is as follows: If A>B then print A else print B endif is A>B Print B Print A Y N
  • 22. Relational Operators Relational Operators Operator Description > Greater than < Less than = Equal to  Greater than or equal to  Less than or equal to  Not equal to
  • 23. Example 6  Write an algorithm that reads two values, determines the largest value and prints the largest value with an identifying message. ALGORITHM Step 1: Input VALUE1, VALUE2 Step 2: if (VALUE1 > VALUE2) then MAX  VALUE1 else MAX  VALUE2 endif Step 3: Print “The largest value is”, MAX
  • 24. Example 6 MAX  VALUE1 Print “The largest value is”, MAX STOP Y N START Input VALUE1,VALUE2 MAX  VALUE2 is VALUE1>VALUE2
  • 25. LOOPS  Computers are particularly well suited to applications in which operations are repeated many times.  If the same task is repeated over and over again a loop can be used to reduce program size and complexity
  • 26. Example 7: Write an algorithm and draw a flowchart to calculate 24 .  Algorithm:  Step 1: Base  2  Step 2: Product  Base  Step 3: Product  Product * Base  Step 4: Product  Product * Base  Step 5: Product  Product * Base  Step 6: Print Product
  • 27. Flowchart START Product  Base Print Product STOP Product  Product * Base Product  Product * Base Product  Product * Base Base2
  • 28.  Question: What happens if you want to calculate 2 to the power of 1000?  Answer: Use a LOOP (repeated execution of the same set of instructions)
  • 29. Example 8:  Write an algorithm and draw a flowchart to calculate 24 using a loop approach? Verify your result by a trace table.
  • 30. Algorithm: Step 1: Base  2 Step 2: Power  4 Step 3: Product  Base Step 4: Counter  1 Step 5: While Counter < Power Repeat Step 5 through step 7 Step 6: Product  Product * Base Step 7: Counter  Counter +1 Step 8: Print Product
  • 31. START Product  Base Counter  1 Print Product STOP Y is Counter < Power Product  Product * Base Counter  Counter + 1 N Base  2 Power 4
  • 32. TRACING BASE POWER PRODUCT COUNTER COUNTER < POWER STEP 1: 2 ? ? ? ? STEP 2: 2 4 ? ? ? STEP 3: 2 4 2 ? ? STEP 4: 2 4 2 1 T STEP 5: 2 4 2 1 T STEP 6: 2 4 2x2=4 1 T STEP 7: 2 4 4 1+1=2 T STEP 5: 2 4 4 2 T STEP 6: 2 4 4x2=8 2 T STEP 7: 2 4 8 2+1=3 T STEP 5: 2 4 8 3 T STEP 6: 2 4 8x2=16 3 T STEP 7: 2 4 16 3+1=4 F STEP 5: 2 4 16 4 F STEP 8: print 16. Step 1: Base  2 Step 2: Power  4 Step 3: Product  Base Step 4: Counter  1 Step 5: While Counter < Power Repeat Step 5 through step 7 Step 6: Product  Product * Base Step 7: Counter  Counter +1 Step 8: Print Product
  • 33.  Example 10: Write down an algorithm and draw a flowchart to find and print the largest of three numbers. Read numbers one by one. Verify your result by a trace table. (Use 5, 7, 3 as the numbers read)
  • 34. Algorithm  Step 1: Input N1  Step 2: Max  N1  Step 3: Input N2  Step 4: If (N2>Max) then Max = N2 endif  Step 5: Input N3  Step 6: If (N3>Max) then Max = N3 endif  Step 7: Print “The largest number is:”,Max
  • 35. Flowchart & Tracing START INPUT N1 MAXN1 INPUT N2 N2>MAX MAXN2 INPUT N3 MAXN3 Print “Largest Number is”, MAX STOP N3>MAX N Y N Y N1 N2 N3 Max N2>Max N3>Max Step1: 5 ? ? ? ? ? Step 2: 5 ? ? 5 ? ? Step 3: 5 7 ? 5 T ? Step 4: 5 7 ? 7 T ? Step 5: 5 7 3 7 F F Step 6: 5 7 3 7 F F Step 8: Print  Largest Number is 7
  • 36.  Example 11: Write down an algorithm and draw a flowchart to find and print the largest of N (N can be any number) numbers. Read numbers one by one. Verify your result by a trace table. (Assume N to be 5 and the following set to be the numbers {1 4 2 6 8 })
  • 37. Algorithm:  Step 1: Input N  Step 2: Input X  Step 3: Max  Current  Step 4: Counter 1  Step 5: While (Counter < N) Repeat steps 5 through 8  Step 6: Counter  Counter + 1  Step 7: Input X  Step 8: If (X > Max) then Max  X endif  Step 9: Print Max
  • 38. N X Max Cou nter Count er < N Next > Max Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 Step 7 Step 8 Step 5 Step 6 Step 7 Step 8 Step 5 Step 6 Step 7 Step 8 Step 5 Step 6 Step 7 Step 8 Step 5 Step 9 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 1 1 1 1 1 1 4 4 4 4 2 2 2 2 6 6 6 6 8 8 8 1 1 1 1 1 4 4 4 4 4 4 4 4 6 6 6 6 8 8 8 output 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 T T T T T T T T T T T T T T F F F F T F F F F F F T T F F T T F START Input N, X Max  X Print Max STOP Y Counter < N N Counter 1 Counter  Counter +1 Input X X>Max Y N Max  X 1 2 3 4 5 6 7 8 9 Tracing How many times will steps 4, 6, and 7 be executed?
  • 39. Do Loops  It is convenient to introduce a special type of loop that is headed by a special macroinstructions.  This terminology comes from FORTRAN , although many programming languages have this type of loop.
  • 40.  For example : BASIC DO K=1 to N {body of loop} END;  FORTRAN Do n K=1 , N {body of loop} n CONTIOUE
  • 42.  Example : A company has 80 employees give a flowchart that  finds the average salary and the number of employees earning above the average salary. Observe that the salaries are read into an array, SALARY. Next, the average salary, AVG, is calculated.  Then each salary , SALARY(K), is compared with AVG to obtain the number NUM of salaries grater than AVG.
  • 45.  Prob. 1. Write an algorithm and draw a flowchart to print the square of all numbers from 1 to10.  Prob. 2. Write an algorithm and draw a flowchart to print the SUM of numbers from LOW to HIGH. Test with LOW=3 and HIGH=9.  Prob. 3. Write an algorithm and draw a flowchart to print all numbers between LOW and HIGH that are divisible by NUMBER.  Prob. 4. Draw a flowchart for a program that reads 10 numbers from the user and prints out their sum, and their product.
  • 46.  Prob. 5. Write an algorithm and draw a flowchart to count and print all numbers from LOW to HIGH by steps of STEP. Test with LOW=0 and HIGH=100 and STEP=5.  Prob. 6. Write an algorithm and draw a flowchart to print the multiplication table for 6's. i.e. ---- 1  6 = 6 ---- 2  6 = 12 … ---- 12  6 = 72  Prob. 7. Write an algorithm and draw a flowchart that will find and print the product of 3 numbers.
  • 47.   Prob. 8. Write an algorithm and draw a flowchart that will find and print  The factorial of NUMBER is FACTORIAL.  Test the flowchart for NUMBER=5.