unsigned long Factorial(int n) { unsigned long f = 1; for (int i = n; i >= 1; i--) f *= i; return f; // this is the answer }
n! = n * (n-1)!
unsigned long Factorial(int n) { if (n <= 1) // base case return 1; else return (n * Factorial(n-1)); }
int Fib(int n) { int n1 = 1, n2 = 1, n3; int i = 2; while (i < n) { n3 = n1 + n2; n1 = n2; n2 = n3; i++; } return n2; }
int Fib(int n) { if (n <= 0) return 0; // base case else if (n == 1) return 1; // base case else return Fib(n-1) + Fib(n-2); // recursive computation }