14 Code a recursive solution for Exercise 11d and provide a

14. Code a recursive solution for Exercise 11(d), and provide a driver program to test your solution.

11. d) Give the base case, reduced problem, and general solution of the recursive algorithm for:

d. The sum of the integers from a to b, a > b.

Solution

Hi friend, you have not mentioned about programming.

I have implemented in Java.

Please let me know in case of any issue.

#############   RangeSum.java ##########

public class RangeSum {

  

   /*

   * Precondition: a > b

   */

   public static int sumRange(int a, int b){

      

       // base case

       if(a == b)

           return a;

      

       // recursive call

       return a + sumRange(a-1, b);

   }

}

###########   SumRangeTest.java ###########

public class SumRangeTest {

  

   public static void main(String[] args) {

      

       System.out.println(\"Sum in range (15, 7): \"+RangeSum.sumRange(15, 7));

   }

}

/*

Sample run:

Sum in range (15, 7): 99

*/

14. Code a recursive solution for Exercise 11(d), and provide a driver program to test your solution. 11. d) Give the base case, reduced problem, and general so
14. Code a recursive solution for Exercise 11(d), and provide a driver program to test your solution. 11. d) Give the base case, reduced problem, and general so

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site