CSC126 Tutorial 1
CSC126 Tutorial 1
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:
Pseudocode:
Start
1. Read the radius, r
2. Calculate area, A using formula:
A=3.14*r*r
3. Display area, A of the circle
End
Flowchart:
Start
Read radius, r
Calculate area, A:
A = 3.14*r*r
Display area, A
A
End
Example: Design an algorithm to determine the greater number between two numbers
Pseudocode:
Start
1. Read the number, A and B
2. If A>B, then display “A”
3. Else, display “B”
End
Flowchart:
Start
Yes No
If
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”; if the result
is negative, display “Negative”; if the result is 0, display “Zero”.
Task 5: 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 6: Write an algorithm to find the largest value of any three numbers