5.31 · exercise

fibonacci goes large

Compute the fiftieth Fibonacci number. It is 12,586,269,025, which is the point: that does not fit in 32 bits, so this loop is why the x registers exist.

Keep the classic sliding pair: a and b start as 0 and 1, and fifty times over, the new value is a + b, then the pair slides forward. When the loop ends, a holds the answer.

what is checked

  • fib(50) printed on its own line
  • the program exits cleanly
  • the loop builds it (answer not written in)

Specification

args
stdoutprints the expected output
exitexits with the expected code
sourceuses add
sourcecomputes the result (does not hardcode it)

Checked by running your program against expected behavior, never by matching a stored solution.

loading editor...
Open in playground