Question: PLEASE THE CODE IS IN JAVA Question 2: Implementing a Recursive Function (10 points) Write recursive function, recursionprob( n), which takes a positive number as

PLEASE THE CODE IS IN JAVA PLEASE THE CODE IS IN JAVA Question 2: Implementing a RecursiveFunction (10 points) Write recursive function, recursionprob( n), which takes a positivenumber as its argument and returns the output as shown below. The

Question 2: Implementing a Recursive Function (10 points) Write recursive function, recursionprob( n), which takes a positive number as its argument and returns the output as shown below. The solution should clearly write the steps as shown in an example in slide number 59 and slide number 60 in lecture slides. After writing the steps, trace the function for "recursiveprob(5)" as shown in an example slide number 61. - The problem is to find the sum for a given vale of ' n ' such that: - sum =1+2+..+n - When n is 1 , the answer is 1 , when n is 2 , the answer is 1+2=3, when n is 3 , the answer is 1+2+3= 6 , when n is 4 , the answer is 1+2+3+4=10 and goes on... - Using Recursion: - Step 1: The base cases is when n is 1, the result is 1 . - Step 2: Base Case: if (n==1), return 1 . - Step 3: Function implementation for Base Case: - int sum(n){ if (n==1) { return 1;}} - Step 4: Using Recursion: - When n is 2 , it is equal to sum of when ((n is 1)+2). It is (n1)+n when n is 2 . - When n is 3 , it is equal to sum of ((n is 1)+(n is 2)+3). So, it is (n2)+(n1)+n when n is 3 . - When n is 4, it is equal to sum of ((n is 1)+(n is 2)+(n is 3)+4). So, it is (n3)+(n2)+(n1)+n. - The repetitive logic is adding n with previous value of sum of (n1). Solve Using Recursion Slide 60 Using Recursion: - Step 5: The recursive logic is: - when (n greater than 1)sum(n1)+n - Step 6: Recursion Implementation: 60

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!