Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL 10 High Performance Expert Techniques For Query Optimization High Availability And Efficient Database Maintenance

Authors: Ibrar Ahmed ,Gregory Smith ,Enrico Pirozzi

3rd Edition

1788474481, 978-1788474481

More Books

Students also viewed these Databases questions

Question

2. Ask questions, listen rather than attempt to persuade.

Answered: 1 week ago

Question

Which are non projected Teaching aids in advance learning system?

Answered: 1 week ago

Question

politeness and modesty, as well as indirectness;

Answered: 1 week ago