Question: Implement a program that calculates the following function based on a value n entered by a user. Write a recursive function that computes n *

Implement a program that calculates the following function based on a value n entered by a user. Write a recursive function that computes n * n/3* n/9* n/27* n/81... where n is a nonnegative integer, n/x is integer division and the quotient is always a multiple of 3 from the previous quotient. The sequence repeats as long as n/x >0. For example:
for n=27 : 27*9*3*1=729
for n=8 : 8*2=16
for n=100: 100*33*11*3*1=108900
The function prototype should be: int recursive(unsigned int n);
Sample run 1:
Input: 27
Result: 729
Sample run 2:
Input: 1
Result: 1
Solution
Note: The following code optimizes the solution to avoid any final recursive call that multiplies the result by 1.
int recursive(unsigned int n)
{
if
(
n <=
3)
{
return 1
;
}
return
;
}

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 Programming Questions!