recursão

Recursive number sequence in Java

I am needing to make a numerical sequence in recursive mode which, after arriving at the n number (5, in the example), starts ... a >= 5){ return 1; } else{ return nSequencia(iSequencia + 1); } } }

Recursive algorithm for calculating arithmetic mean

I am making an algorithm that has to calculate the average of the values of a list, but with what I did it does not present t ... not. def media(l,s=0): if len(l) == 0: return s else: return media(l[1:],s+l[0]) / len(l) media()

Recursive function

Can anyone help me with this recursive function? It's for her to calculate the maximum common divisor between two numbers but ... lt;0){ return 0; } else{ aux=mdc(n, m % n); return aux; } }

What is a recursive method?

Is the variable resultado inside the for recursive? #include <stdio.h> int main(void) { int N,i; double resultado=0.0 ... p;N); for (i=0; i<N; i++) { resultado= 1.0 / (resultado+2); } printf("%0.10lf\n",1.0+resultado); return 0; }

What is the difference between recursion and tail recursion?

In functional programming languages, it is said that it is possible to prevent stack overflows by using "tail recursion". But what is the difference between normal recursion and tail recursion?

Calculate the cartesian product with functional programming

I am writing a function in Python that receives two lists and returns a list of tuples with the cartesian product of the inpu ... lista2) I can't use repeat loops, as it's much more intuitive. It is a question of functional programming, no ties, etc...

Functional programming: recursive function to calculate the rest of the division between two positive integers in ELM

Hello, I'm having a hard time making a recursive function that passes as a result the rest of dividing two integers in ELM. I ... apply a recursive function that brings the same result ! Could you help me ?! The language used is Elm derived from Haskell !

Recursion-add numbers in an array

I'm doing the FreeCodeCamp course and in the subject of recursion I came across this code: function countup(n) { if (n &l ... this line? Because for me, from the moment I call the function countup(n - 1), What is below it is not executed. Can me help?

Counting sequence of numbers recursively in a C array

So I'm having the following problem: I need to count how many decreasing sequences of numbers exist in an array recursively ... trix, however in my function I can only return the value 2. Would anyone know how to tell me what I'm doing wrong? Thank you.

Recursive function to calculate the mean

I made this function media() which calculates the average of the elements present in a vector of 5 elements. However, the fun ... ; } int media(int vet[], int tam) { if (tam == 0) return 0; else return vet[tam - 1]/5 + media(vet, tam - 1); }

Doubt about recursion in C

I am learning about recursion, using the C language, and I have to do the following exercise: Design a recursive function t ... 10) + soma(n/10)); } But I did not understand exactly the logic of this code, so I thank anyone who can explain to me =]

Implicit recursion When assigning the return of a function to a variable?

Talk guys, I'm starting Studies in Python and I came across a slightly strange behavior for me. It is as follows: I have a fi ... finally if I declare only a = trial_search(x_best,h,0.1) As a result a -> [0.09466141654703604, 0.531150378103339]

Recursion For list inversion in Python

I am trying to create a recursive function that reverses the order of a given list. Since I am a beginner, I believe I am mak ... change during execution, thus returning only the last element of the original list, see code above. I really got stuck here.

Recursive function of natural numbers is showing negatives

I need a recursive function (exercise) that prints all natural numbers between A and B: def cont(a, b): if a < b: ... int(a) cont(a + 1, b) cont(-3, 12) The problem is that the way I did, the negative numbers are being printed as well.

Calculating pi with python and using recursion

Calculate pi by the Formula pi=(s*32)**(1/3), being s=(1/1^3)-(1/3^3)+(1/5^3)... Quantity of s determined by the user. It sh ... erm you want to calculate: ")) if test(n): a = 2 p = 1 print("Total: ", sum(n, a, p)) else: print("Error")

Recursive algorithm to check if an element belongs to a list

I have to make a recursive function that receives a list and a target element, and returns True, if the element is in the lis ... if (primeiro == alvo): return True elif restante == alvo: return True else: return False

Hanoi Tower-How does this recursive solution work?

Could anyone explain to me the logic of this recursive function? I am not able to understand from if down. The code solves th ... ,dest)) toweOFhanoi(disc - 1,aux,ori,dest) print('Move disc {} from tower {} to the tower {}'.format(disc,ori,dest))

How to check the efficiency of these 2 functions in C++?

How to determine which of these two functions is the best choice for implementation? 1: int X(int x){ if(x<=0) retu ... =x;++i) soma+=i; return soma; } How to determine the complexity equations and solve them? Or is there another method?

How to improve this list flattening function

In school we are studying recursion, but of course this is never obvious. We have to create a function that "flatten" the lis ... ttened_list is a global list, which you have to call exactly like that in order for the function to work. Can I improve this?

How to calculate the values of a function in a whole range being known only the values in the integer points?

Can anyone help me, please? I am trying to write a function in Python (I use 3) that implements the following code that is i ... cause it is still recursive. Can you help me as to this error and as to a good implementation of this problem? Thank you all.