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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!