Ch03 Flowchart and Pseudo Code Examples
Ch03 Flowchart and Pseudo Code Examples
Ch03 Flowchart and Pseudo Code Examples
input rate
output sum
pay = hours * rate
End
print pay
End
1 2
Average of 3 Numbers - sequence Calculate Pay with Overtime - selection
Start
Begin
input x
input y
input x input z
input y sum = x + y + z input hours, rate
input z avg = sum / 3.0
print avg
End
sum = x + y + z
F
avg = sum / 3.0
hours ≤ 40
T
print avg
pay = 40 * rate +
pay = hours * rate (hours - 40) * 1.5 * rate
End
print pay
Begin
input hours, rate
if hours ≤ 40 then
pay = hours * rate
else
pay = 40 * rate + (hours – 40) * rate * 1.5
print pay
End
3 4
Average of 10 Numbers – iteration with a while loop Average of 10 Numbers – iteration with a for loop
Begin
sum = 0
i = 0 for i = 1 to 10
sum = 0 input x
sum = 0 sum = sum + x
avg = sum / 10.0
print avg
i End
while i < 10 1
1 10
F
1
T
Begin Begin
i = 0 i = 0
sum = 0 sum = 0 avg = sum / 10.0
while i < 10 a: if i ≥ 10 goto b
input x input x
sum = sum + x sum = sum + x
++i ++i print avg
avg = sum / 10.0 goto a
print avg b: avg = sum / 10.0
End print avg
End
5 6
Flowchart for Function or Subroutine Module
Begin
Begin
print “Input 3 numbers: ”
input a, b, c
print “input 3 numbers” avg = average(a, b, c)
input a, b, c print “Average is ”, avg
End
Average
End
Average
Begin Average(a, b, c)
sum = a + b + c
avg = sum / 3.0
return avg
sum = a + b + c End
avg = sum / 3
Exit