Computer Flow Charts
Computer Flow Charts
DAY 2
Mathematics CPD – 2019.
TOPIC: COMPUTER
(Pseudo-codes and Problem-solving)
PRESENTERS:
MR. BANDA S
Introduction
In the previous presentation we learnt how to draw simple
flow charts and how to solve simple logical problems. Such
problems did not involve making many decision but rather
doing task sequentially i.e. one after the other. This is known
as the sequence control structure.
Introduction Cont’d
In this presentation however, we will first learn how to write simple
problem solving programs in a language called pseudo-code. We will
then learn how to solve slightly advanced problems that involve a
step or steps to make decision to determine the next step.
We will also learn how to solve problems that involve repeating a
certain task until a certain condition is met.
PSEUDOCODE
What is a Pseudo-code?
Pseudo-code Cont’d
A Pseudo-code is a set of statement written in a human
readable language (usually English like phrases) but expressing
the processing logic of a program.
≠ is not equal to
Example 1
Write a Pseudo code for calculating the Area of the
square:
Solution
Note that one may not be given the formula but it is important to
know it because after decision statement it must be shown (𝑨𝒓𝒆𝒂 =
𝒍^ 𝟐) as shown in the solution.
Solution 1 Cont’d
Example 2
Write a pseudo-code for calculating volume of a cone.
Solution 2
Example 3
Write a Pseudo code for calculating the area of a circle whose
radius is r:
Solution
For this one in some instances one may not be given the formula
but it is important to know it because after decision statement it
must be shown (𝑨𝒓𝒆𝒂 = 𝝅 *r*r) as shown in the solution.
Solution 3
Start
Enter radius
If radius<0
Then print error message
re-enter positive radius
Else Area = 𝜋*square radius
End if
Display Area
Stop
Group Activity
IF <condition> THEN
sequence 1
ENDIF
Example:
IF a>0 THEN
Print a
IF…THEN statement Cont’d
Example 1
IF a>b THEN
Print a
ELSE
Print b
The IF...THEN…ELSE Cont’d
Example 2
Write the pseudo-code and draw the flow diagram
for a program that displays pass when the scores
is greater than 40 and fail when it is 40 or below.
The IF…..THEN……ELSE Cont’d
Solution
(C) The NESTED IF statement is used if more than two
options are available.
STRUCTURES:
The NESTED IF statement Cont’d
The NESTED IF statement Cont’d
Example 3
Write the pseudo-code and draw the flow chart
for a program that would categorize pupils
performance in mathematics as follows:
80 and above: Excellent, 60-79: Good, 40-59: Fair,
0 – 39: poor.
Solution flow chart
Repetition(Looping) in a program
Some programs involve repeating a task until a certain
condition is met. This is known as looping or iteration.
Pseudo code
The syntax is:
WHILE (a condition is
true)
A statement or block
of statements
ENDWHILE
Example 4
Write the pseudo code for finding the sum greater than or equal 50 of
consecutive prime numbers.
(b) The REPEAT…….UNTIL loop
unlike the while loop, repeat……until allows the statement within it to be
executed at least once since the condition is tested at the end of the loop.
Pseudo code
REPEAT
A statement or block of statements
UNTIL a true condition
Example 6.