Skip to content

Commit

Permalink
recursive function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jainkhere committed Feb 22, 2022
1 parent d2617f1 commit 2e5a3a8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions recursion.c
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));
}

0 comments on commit 2e5a3a8

Please sign in to comment.