0
Sum of integers of an array using Recursion method ??
i want some help to build a Recursive function which takes an input array then returns the sum of its elements (without using loops) EX: size =3 elements= 10, 20, 30 sum = 60
4 Réponses
+ 12
Here your are:
https://code.sololearn.com/c55ecj0PvHK8/?ref=app
+ 1
Think of this: The sum of the elements of an array is equal to the first (or last, or any) element plus the sum of the rest of elements.
0
def sumRec(list):
if list:
return list[0] + sumRec(list[1:])
else:
return 0
0
//not in any language but easily translatable :
int sum(int tab[n],int n,int id){
if(id==n){
return 0;
}
return tab[id]+sum(tab,n,id+1);
}