Time remaining:
Write a recursive method that will calculate the sum of the arrays

Programming
Tutor: None Selected Time limit: 1 Day

  1. Write a recursive method that will calculate the sum of the arrays.  Remember that the array can be any size, and that the recursive method should keep going from element to element, always decreasing the index, while adding the contents of each element in the array.

Apr 12th, 2015

Java Code 

public static int sum(int[] array,int index){ 

if(index ==0){

  return array[0];}

else{

  return array[index]+ sum(array, index -1);

  }

}


C Code:

int arr_sum( int arr[], int n, int sum )

{     // must be recursive

  if (n < 0) {

   return sum;

  } else {

  sum += arr[n];

  }

   return arr_sum(arr, --n, sum);

}




Apr 12th, 2015

Studypool's Notebank makes it easy to buy and sell old notes, study guides, reviews, etc.
Click to visit
The Notebank
...
Apr 12th, 2015
...
Apr 12th, 2015
Dec 7th, 2016
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer