Branching algorithms
Answers are for parents and teachers.
1
Write, in the short form and in words, an algorithm that calculates the cube of a given whole number a if a is divisible by 3.
Start; input a; if the remainder of a divided by 3 is 0, calculate a · a · a and output it; end.
2
Write in words the branching algorithm for finding the smallest of three numbers a, b, c.
m = a; if b < m, m = b; if c < m, m = c; output m.
3
What is the taxi fare (15 000 up to 5 km, then 2 000 so‘m per km) for 12 km?
29000
4
The sign function: y = –1 (x<0), 0 (x=0), 1 (x>0). Write y for x = 0 and x = 3.5.
0, 1