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

label Programming
account_circle Unassigned
schedule 1 Day
account_balance_wallet $5

  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

Did you know? You can earn $20 for every friend you invite to Studypool!
Click here to
Refer a Friend
...
Apr 12th, 2015
...
Apr 12th, 2015
Jun 23rd, 2017
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