miércoles, 8 de abril de 2015

#Mastery21 use of recursion

You use recursion in functions for repetitive algorthms. Basically griting a function inside itself for a sort of loop, making your code smaller and cleaner.

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: palindromesstandard deviation

No hay comentarios:

Publicar un comentario