

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Recursion is a process in which a function calls itself directly or indirectly to solve a problem. It provides an elegant way to solve problems that can be divided into smaller, similar sub- problems. Characteristics of Recursion
int main () { int num; printf("Enter a number: "); scanf("%d", &num); printf("Factorial of %d is %d\n", num, factorial(num)); return 0; }
2. Fibonacci Series (Recursive) The Fibonacci series is defined as: F(n)=F(n−1) +F(n−2) With base cases: F (0) =0, F (1) = 1 Example #include <stdio.h> // Recursive function to find Fibonacci number int fibonacci(int n) { if (n == 0) return 0; // Base case if (n == 1) return 1; // Base case return fibonacci(n - 1) + fibonacci(n - 2); // Recursive case } int main() { int n, i; printf("Enter the number of terms: "); scanf("%d", &n); printf("Fibonacci series: "); for (i = 0; i < n; i++) {