Sequence Algorithms Examples
Sequence Algorithms Examples
Output TOTAL
- narrative -pseudocode
What is Prompt and Prompt and Promptand
Let TOTAL the input enter the three enter three INPUT A, B, C
A + B+ C
instruction? numbers numbers A,
B, C
What is the Calculate the LET TOTAL=A
Calculatethe
processing Sum of the total using the +B+C
instruction? three numbers formula:
TOTAL =A+ B
PRINT What is
C
Display the sum Output TOTAL PRINT TTAL
the output of the three
instruction? numbers
The flowchart for the
example in Figure 12.6 will have the sa1
symbols as the one we have seen before, but the content or
boxes will be changed to reflect u
the more refined algoritnnl.
END
220
Refining an algorithm
Problem 4
Convent a temperature in degrees Celsius to degrees Fahrenheit.
Possible algorithmn
The summary for the steps to writing the possible algorithm is
shown in Table 12.2.
Start
Table12.2 Converting termperature
Question Algorithm Algorithm Algorithm
- narrative
refined refined further
- pseudocode
What is Enter the Prompt and Prompt and
the input temperature in enter the INPUT C
Prompt and instruction? degrees Celsius temperature in
INPUT C
that you would degrees Celsius
like to convert. C
(The letter C
isthe variable
used to hold
the value
Let F = (32 + 9 *C/5)
of degrees
Celsius.)
What is the Convert to Convert to LETF=
processing degrees degrees (32 +9 C/5)
instruction? Fahrenheit Fahrenheit
by using the by using the
formula: formula: F =
Degrees (32+9*C/5)
PRINT C and Fahrenheit = The letter F
(32 +9 is the variable
degrees Celsius used to hold
/5 the value
of degrees
Fahrenheit
What is Display the Output C and F PRINT C and F
the output temperature
END
instruction? in degrees
Celsius and the
Converted value|
in degrees
Figure 12.7 Flowchart: Convert
Fahrenheit.
temperature
In a flowchart, the algorithm would look like this one in Figure 12.7.