Escolar Documentos
Profissional Documentos
Cultura Documentos
PROGRAM DESIGN
Example 1:
Below is the algorithm to explain the morning
activity for an employee, before going to the
office.
1. Get up from bed
2. Shower
3. Get dressed
4. Have breakfast
5. Drive to the office
Example 2:
Algorithm to make a coffee.
1. Boil water
2. Put coffee into cup
3. Pour boiled water into cup
4. Add sugar
5. Stir the mix
6. Taste it
7. If sugar not enough, repeat
step 4 to add sugar
8. Else coffee is done
Example 3:
Algorithm to solve the problem of calculating the
average of 3 numbers.
Answer:
1. Input the hours work and pay rate
2. Calculate salary using the formula:
Salary= hours work x pay rate
3. Print Salary
• Example 5:
Write an algorithm to solve the problem of
calculating the area for a circle based on
problem analysis given below:
Problem Analysis:
Input : radius of circle
Process : Calculate area for a circle using the formula -
Area of circle= 3.14 x radius x radius
Output: Area of circle
Answer:
1. Input radius of circle
2. Calculate area of a circle using formula:
Area of circle= 3.14*radius*radius
3. Print Area of circle
TYPES OF ALGORITHM
Pseudo Code
Flowchart
PSEUDO CODE
Uses English like statements in place of the
flowchart graphical symbols.
It is easier to code a program from it than from
flowchart.
It is not tied to any programming language.
It is easy to modify but not graphical, difficult
to use for logically complex problems, and
slower to create.
Pseudo Code
Example 1
Write a pseudo code to calculate the total of 3 numbers
entered by user.
Start
Program START
Answer:
START
Input hours _work, pay_rate
Salary= hours_work * pay_rate
Print Salary
END
Pseudo Code
• Example 3:
Write a pseudo code to solve the problem of
calculating the area for a circle based on
problem analysis given below:
Problem Analysis:
Input : radius of circle
Process : Calculate area for a circle using the formula -
Area of circle= 3.14 x radius x radius
Output: Area of circle
Pseudo Code
Answer:
START
Input radius_of_circle
Area_of_circle= 3.14*radius*radius
Print Area_of_circle
END
FLOWCHART
• graphic representations of the algorithm
• shows the flow of processing from the
beginning to the end of a solution
• each block in a flowchart represents one
instruction from an algorithm
• Flow lines indicate the direction of the data
flow
Flowchart
• Symbols used
Symbol Function
Start/ end
process
Input/ output
condition
Flow lines
connector
Flowchart
• Example 1:
Draw a flow chart based on the problem given
below:
Calculate the salary of an employee who
works hourly basis. The formula to be used is
Salary = hour works * pay rate
Flowchart
Answer: start
Print Salary
end
Flowchart
• Example 2:
Draw a flow chart based on the problem given
below:
Add two number that entered by user.
Answer:
Exercise 1:
a) In the flowchart above, what will be the first action you take?
b) If you haven’t gone 50 steps yet, what will you do next?
c) If you’ve gone 50 steps, what do you do?
Exercise 2:
• On a separate sheet of paper, make a flowchart organizing the “flow” of
getting ready to go to school in the morning.
• Be sure to include the following steps in your chart, but don’t be afraid to
add other things if you need them!