Recursion in C
A function calling itself, with a base case to stop.
Easy
unsigned long fact(unsigned n) { return n <= 1 ? 1 : n * fact(n - 1); }
Each call uses stack — avoid deep recursion on microcontrollers.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.