Learn C Programming

Lesson 3 of 7 · Recursion

Module 8 · Recursion

Recursion Patterns: Factorial, Fibonacci, Digits

Free with an accountReading

Kenji wrote Fibonacci exactly as the maths defines it: each number is the sum of the two before it. Four lines, no loop.

Sign in to read

This lesson is free, with an account

An account costs nothing and opens every lesson in this track that is not marked Pro, on every device you read on.

What is inside Recursion Patterns: Factorial, Fibonacci, Digits

  1. Digits: the last one with % 10, the rest with / 10
  2. Print the digits in order: call first, print after
  3. Euclid's gcd: the answer passes straight up
  4. Power, and fast power by squaring
  5. Fibonacci: two calls in every call
  6. The call tree of fib(5), counted
  7. Hanoi: the recursion with no simple loop
  8. One call or two: depth and total are different questions