Tutorial Computer Programming 1
Tutorial Computer Programming 1
Section A
1. What is an algorithm?
The step by step sequence of instructions that describe how the data is to be processed to
produce the desired output.
3. Can there be more than one algorithm for a single problem? Give reason for your answer.
Yes, because different algorithm for a single problem will only differ in their efficiency of
the problem solving. Give example = path from a to z, there are many alternative ways
4. Determine a step-by-step procedure (list the steps) to do the following tasks:
a) Fix a flat tire. 1. Take out the jack & spare tire.
2. Jack-up the car.
3. Take off the flat tire.
4. Put on the spare tire.
5. Lower the jack.
6. Replace the jack & put the flat tire away.
Start
Input the
radius of
the circle,
Radius = r
Display the
area of the
circle
End
Start
Input the
value A, B
and C
No Yes
Is Is Is
B>C? A>B? A>C?
No Yes
No Yes
End
Input the
temperature in
Fahrenheit, F
Convert Fahrenheit to
Celsius, C:
C = (F-32) (5/9)
Display the
temperature
in Celsius
End
Section B
Complete the problem definition for the following problems. Identify what is the required information,
what are the data needed, what formulas are involved. Write algorithm (pseudocode and flowchart) for
each of the following problems.
Pseudocode:
1. Input the side of squares A, B and C.
2. Calculate the area of the squares by squaring its side:
Area =side^2
3. Display the areas of the three squares.
Start
Print the
area of the
three
squares
End
2. Task: Calculate the total salaries for 5 employees. The salary is paid based on the hours they worked
and the rate per hour using the formula salary = rate per hour x hours worked. Each employee is being
paid with the same rate.
Pseudocode:
1. Input the hours worked for each employee and rate per hour
2. Calculate the salary of each employee by multiplying rate per hour with hours worked:
Start
3. Calculate the temperature in Celsius. Temperature in Fahrenheit will be entered. The formula is:
End – 32).
Temperature in Celsius = 5/9 (temperature in Fahrenheit
Pseudocode:
Start
Input the
temperature in
Fahrenheit, F
Convert Fahrenheit to
Celsius, C:
C = (5/9) (F-32)
Print the
temperature
in Celsius
End