File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Roadmap/06 - RECURSIVIDAD/python Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ #06git
2+ def regresiva (n ):
3+ if n == 0 : # caso base
4+ print (n )
5+ else :
6+ print (n )
7+ regresiva (n - 1 ) # llamada recursiva
8+
9+ regresiva (100 )
10+
11+ # Ejercicio extra 1
12+ def factorial (n ):
13+ if n == 1 : # caso base
14+ return 1
15+ else :
16+ return n * factorial (n - 1 ) # llamada recursiva
17+
18+ numero = int (input ("Ingresa un numero para hayar el factorial: " ))
19+ print (factorial (numero ))
20+
21+ # Ejercicio extra 2
22+
23+ def Fibonacci (n , x , a ):
24+ y = a
25+ if n == 2 : # caso base
26+ return y
27+ elif n == 1 :
28+ return 0
29+ else :
30+ z = x + y
31+ x = y
32+ y = z
33+ fi = Fibonacci (n - 1 , x , y ) # llamada recursiva
34+ return fi
35+
36+ posicion = int (input ("Ingresa una posicion para la secuencia de fibonacci: " ))
37+ print (Fibonacci (posicion , 0 , 1 ))
You can’t perform that action at this time.
0 commit comments