Lab 2: Problem Solving using Algorithm
Objectives:
1. To illustrate algorithm before writing C++ program.
a. Design a simple algorithm using pseudocode
b. Design a simple algorithm using flowchart
Pseudocode
A sequence of activities to be processed for getting desired output from a given input
Before writing a pseudocode for a problem, one should find out what is/are the inputs and
what is/are expected output
It uses short terms or simple English
While writing pseudocode we will use following symbol for different operations:
“+” for Addition
“-” for Subtraction
“*” for Multiplication
“/” for Division
“ ” for assignment. For example, A x*3 means A will have a value
of x*3
example pseudocode
Problem : Find the area of a Circle of radius r (A = r2)
Input : Radius r of the Circle
Expected Output : Area of circle
Pseudocode:
Start
1. Read/input/get the Radius r of the Circle
2. Area 3.14*r*r
3. Display Area
End
Flowchart
A type of diagram that represents a workflow or process
A flowchart can also be defined as a diagrammatic representation of an algorithm, a step-by-
step approach to solving a task
Common flowchart symbols:
Example flowchart
Problem : Find the area of a Circle of radius r (A = r2)
Start
Read r
Area = 3.14*r*r
Display Area
End
Exercises
Task 1: Write the pseudocode and design the flowchart to read two numbers and find their sum
Task 2: Write the pseudocode and design the flowchart to convert Fahrenheit to Celsius
Celsius = (F-32) x (5/9)
Task 3: Write pseudocode and design the flowchart to find the greater number between two numbers
Task 4: Write pseudocode and design the flowchart that display the area of a rectangle by accepting
length and width from the user.
Task 5: Write pseudocode and design the flowchart to find the largest value of any three numbers