Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The product of n can be written as illustrated below, where productOf(1) = 1 is the base case for the recursive formulation of this computation.

The product of n can be written as illustrated below, where productOf(1) = 1 is the base case for the recursive formulation of this computation.

productOf(n) = n * (n-1) * ... * 3 * 2 * 1

for any integer n > 0

productOf (n) = n * productOf(n-1)

productOf(1) = 1

---------------------------------------------------------------------

In java this recursive computation can be programmed in two ways shown below. The difference is that the intermediate value of product is not stored.

public static int productOf(int n)

{

int product;

if ( n==1)

product = 1;

else product = n * productOf(n-1);

return product;

}

---------------

public static int productOf(int n)

{

if ( n==1)

return 1;

else

return n * productOf(n-1)

}

Use both examples with n = 10 and write a main method so both examples of the code work. Annotate the code to show that you understand the program(s) and submit. Note that no credit will be given for submissions that do not compile/run or are not correctly annotated. **java**

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

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions

Question

Wood consists of what two(2) components?

Answered: 1 week ago

Question

=+j Improve the effectiveness of global and virtual teams.

Answered: 1 week ago