Question
Factorial Function: Write the following functions recusively : unsigned long long factorial (unsigned int n); This function returns n! (read n factorial). n! is calculating
Factorial Function:
Write the following functions recusively:
unsigned long long factorial (unsigned int n);
This function returns n! (read n factorial). n! is calculating by multiplying every number between 1 and n:
n! = n * (n-1) * (n-2) * ... * 3 * 2 * 1
Example: factorial(4)
4! = 4 * 3 * 2 * 1 = 24
Power Function:
Write the following function recursively:
unsigned long long power (unsigned int base, unsigned int n);
This function returns base^n = base * base * base * ... * base (n base values multiplied together) Ex. power(2.0, 4) = 2^4 = 2 * 2 * 2 * 2 = 16
Fibonacci Function:
Write the following function recursively:
unsigned long long fibonacci (unsigned int n);
This function returns the nth fibonacci number in the fibonacii sequence (denoted Fn below)
F0 (fibonacci(0)) = 0
F1 (fibonacci(1)) = 1
F2 sum of F0 and F1 = 0+1 = 1
F3 sum of F1 and F2 = 1 + 1 = 2
F4 sum of F3 and F4 = 1 + 2 = 3
F5 sum of F4 and F5 = 2 + 3 = 5
Please write the above three functions recursively (factorial, power and fibonacci) in C++ code language, thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started