Question: Question 01: a) Write a static method to calculate f(n) recursively. Assume that there will not be any overflow, and the output will fit in

 Question 01: a) Write a static method to calculate f(n) recursively.

Question 01: a) Write a static method to calculate f(n) recursively. Assume that there will not be any overflow, and the output will fit in 64-bit decimal number. This method takes only one integer parameter and outputs a double number. The method should be a public method so that it can be accessed from outside the class. f(n) = 0, if nso 1, if n=1 3, if n = 2 f(n 1) + "-vf(n 2) if n > 2 and n is even (f(n-1))1.000001, if n > 2 and n is odd b) Write another static method to calculate above function iteratively using a loop. You can use an array if you want. Any other ideas are also acceptable. The parameter and return type is same as a) c) Write a method that prints the recursive and iterative version of first 20 f(n) side by side using a printf. Ensure that every f(n) is displayed in a separate line, right aligned with at least 20 characters, and only 2 digit after decimal point is displayed

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!