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.

Checking what this lesson needs for you…

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