-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* @file recursion.c | ||
* @author kunal jain ([email protected]) | ||
* @brief This program has 2 functions | ||
* 1. Factorial function | ||
* 2. Fibonacci number | ||
* @version 0.1 | ||
* @date 2022-02-20 | ||
* | ||
* @copyright Copyright (c) 2022 | ||
* | ||
*/ | ||
|
||
#include<stdio.h> | ||
|
||
|
||
// n! = 0 if n = 0 (base case) | ||
// n! = n * (n-1)! otherwise (recursive case) | ||
|
||
// Function to calculate factorial of n. | ||
int factorial(int n) { | ||
} | ||
|
||
|
||
// Finbonacci series -> 1, 1, 2, 3, 5, 8, 13, 21... | ||
// fib(n) = 1 if n = 1 | ||
// fib(n) = 1 if n = 2 | ||
// fib(n) = fib(n-1) + fib(n-2) otherwise | ||
|
||
// Function to calculate nth fibonacci number | ||
// using recursion | ||
int fibonacci(int n) { | ||
} | ||
|
||
// Function to calculate nth fibonacci number | ||
// without using recursion | ||
int fibonacci_loop(int n) { | ||
} | ||
|
||
int main(void) { | ||
printf("Factorial of 5 -> %d\n", factorial(5)); | ||
printf("Fibonacci of 7 -> %d\n", fibonacci(7)); | ||
printf("Fibonacci of 7 -> %d\n", fibonacci_loop(7)); | ||
} |