Assignment 1-2.1.2 Pseudocode and Flowcharts
Assignment 1-2.1.2 Pseudocode and Flowcharts
2.1.2 Pseudocode
1. State three types of repetition construct available in high level languages, giving a
characteristic of each. [6]
2. Write an algorithm (using either pseudocode or a flowchart) that calculates the amount of
fuel a train will need to complete a journey. The algorithm must:
• ask the user how many kilometres the journey will be
• only continue if the user enters a value greater than zero
• set the amount of fuel to a number 100 times greater than the number of kilometers
• not allow the amount of fuel to be less than 1500
• finally, display the amount of fuel needed. [7]
3. What is the output of the following loop?
Declare total as Integer
Declare number as Integer
total = 25;
number = total DIV 2
For i = 1 to number
total = total – number
OUTPUT (total + “ “ + i)
Next
[5]
4. For each of the following while loops, how many times will the loop execute its body?
Remember that "zero," "infinity," and "unknown" are legal answers.
(i) Declare x As Integer
x = 1
While x < 100
OUTPUT (x & “ “)
x = x + 10
End While
[1]
(ii) Declare max As Integer
max = 10
While max < 10
OUTPUT (“count down: “ + max)
max = max – 1
End While
[1]
(iii) Declare x As Integer
x = 250
count = x MOD 3
While count <> 0
OUTPUT X
Count = count MOD 3
End While
[2]
(iv) Declare x As Integer
x = 2
While x < 200
Output x & “ “
x = x * x
Page 1 of 2
Computer Science Assignment # 1
2.1 Algorithm Design and Problem Solving
2.1.2 Pseudocode
End While
[2]
(v) Declare x as Integer
x = 100
While x > 0
OUTPUT (x DIV 10)
x = x DIV 2
End While
[1]
Page 2 of 2