Factorial and Fibonacci series will be a good example for recursive function as it calls by itself. Let’s discuss about Factorial program here.
#include <stdio.h> int factorial(unsigned int); int main() { int i = 8; printf("Factorial of the number %d is %d\n", i, factorial(i)); return 0; } int factorial(unsigned int i) { if(i < 2) { return 1; } return i * factorial(i - 1); }
Output:
Factorial of the number 8 is 40320
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Output:
Factorial of the number 8 is 40320