Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2017/imperative-programming/4/e/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2017 Imperative programming 4 e Solution by
Codex 0 2026-10-31
procedure OutRat(m,n)
Out.Int(m)
Out.String("/")
Out.Int(n)
procedure OutEgypt(e)
if e.i = 0 then
Out.String("0")
else
for j := 0 to e.i-1 do
if j > 0 then Out.String("+")
Out.String("1/")
Out.Int(e.x[j])Ordinary unpadded decimal output and the greedy Egyptian fraction expansion give
5/7 = 1/2+1/5+1/70 for that input. The final newline is supplied by the caller. Stored duplicate denominators, if present in another valid representation, are printed as separate unit fraction occurrences. New to topics? Read the docs here!