Professional Documents
Culture Documents
Objectives:
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:
Input: Radius, r
Process: A = πr2
Output: Area of circle, A
Pseudocode:
Start
1. Read the radius, r
2. Calculate area, A by using formula:
A = 3.14 * r * r
3. Display area, A of the circle
End
Flowchart:
Start
Read radius, r
Display area, A
End
Example Problem 2:
Input: A, B
Design an algorithm to determine the greater number
between two numbers Process:
1) If A > B
2) If A < B
Output:
1) Display “A”
2) Display “B”
Pseudocode:
Start
1. Read the number, A and B
2. If A > B, then display “A”
3. Else, display “B”
End
Start
Flowchart:
Read A and B
Yes If No
A > B
End
Exercises
Task 2: Write an algorithm to display the area of a rectangle by accepting length and width from the user.
Task 3: Write an algorithm for a program that can prompts user to enter total number of umbrellas he/she
wants to buy. Price of one umbrella is RM15.00. This program will calculate and displays total price of
these umbrellas to user.
Task 4: Write an algorithm to subtract 2 numbers. If the result is positive, display “Positive” and if the
result is negative, display “Negative”.
Task 5: Write an algorithm to subtract 2 numbers. If the result is positive, display “Positive” and if the
result is negative, display “Negative”; if the result is 0, display “Zero”.
Task 6: Write an algorithm to ask user to enter weight. Program will only display status based on below
condition:
• weight >100kg, display “Obese”
• weight < 30kg, display “Underweight”
• others, display “Normal”
Task 7: Write an algorithm to find the largest value of any three numbers