this program is grat example, I have 2 functions and they repeat inside each other, I could have made different functions but they would have recursion in that way.
my WSQ12 is also a great example of recursion.
in this case the program uses de function gcd to determine the greatest comon divisor, and ans is the gratest common divisor itself, in case that the numbers given by the user are not the same (not x==y), the fuction will call itself but with some changes:
else: | |
if(x>y): | |
ans=gcd((x-y),y) | |
else: | |
ans=gcd(x,(y-x)) | |
return ans |
other examples of recución are: palindromes, standard deviation
No hay comentarios:
Publicar un comentario