Lab 2 - Pseudo Code and Flowcharts
Lab 2 - Pseudo Code and Flowcharts
Introduction
In this lab, we will continue to learn the concepts of pseudocode and flowcharts.
Objectives
The purpose of this lab is to enable students to understand the basics of problem solving in
programmatic context. Students will be representing solutions to different problems as
flowcharts and pseudo code.
Tools/Software Requirement
Microsoft Word
Description
What is an Algorithm?
1. Pseudo code
2. Flowchart
What is a Pseudocode?
Pseudocode is a tool that can be used to write a preliminary plan for the development of a
computer program. It is a generic way of describing an algorithm without the use of any specific
programming language syntax. In fact, it serves as an English like way to state an algorithm.
Example: Write a pseudo code for converting temperature entered by the user in centigrade to
Fahrenheit.
Solution:
BEGIN
DISPLAY “Enter Centigrade: "
INPUT centigrade_value
CALCULATE Fahrenheit = (1.8 * centigrade_value) + 32
DISPLAY Fahrenheit
END
What is a Flowchart?
A flowchart provides a detailed picture of the algorithm using special symbols to represent
various program statements. A flowchart will usually be drawn from top to bottom showing the
exact order of the steps. Arrows are used to depict the “flow” of a program.
Rounded rectangles
It represents the terminals of a program (e.g. Start, End)
Parallelograms
It represents the Input and out operation. (e.g. Display a Message,
Read Hours)
A rectangle
It represents process e.g. A mathematical calculation.
A diamond
It represents decision making process e.g. A condition is analyzed,
where answer is usually either True or False.
Flow Lines
Arrow shows the direction of flow of instructions.
Connectors
They are used to join one part of the flowchart with another part
of the flowchart.
The connectors connecting two parts of the same flowchart are referenced using a number (number 1 in
the circle in this case).
Lab Tasks:
Write pseudo codes and draw flowcharts for the following problems:
1. Take a string (sentence in English) as input from the user. Calculate the number of vowels
present in that string and display the result.
To confirm your solution trace through your flowchart and pseudocode with the following test
values to check their accuracy:
2. Take 10 numbers as input from the user. Find out how many numbers in that list are duplicate
and display the result.
To confirm your solution trace through your flowchart and pseudocode with the following
test values to check their accuracy:
3. Take a number “n” as input from the user. Display the first “n” numbers in the Fibonacci
sequence. Fibonacci Sequence: 1,1,2,3,5,8……….(next number is sum of previous two numbers)
To confirm your solution trace through your flowchart and pseudocode with the following test
score values to check their accuracy:
4. Take a number as input from the user and display the number of digits in that number.
To confirm your solution trace through your flowchart and pseudocode with the following test
score values to check their accuracy:
To confirm your solution trace through your flowchart and pseudocode with the following test
score values to check their accuracy:
6. Take a number as input from the user. Find its square root and display it. Your solution should
be accurate to at least 2 decimal places. You should only use the basic mathematical operations
to solve this problem.
To confirm your solution trace through your flowchart and pseudocode with the following test
score values to check their accuracy:
• Input: 16 Output: 4
• Input: 32 Output: 5.66