-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursivas.groot
More file actions
61 lines (49 loc) · 1003 Bytes
/
recursivas.groot
File metadata and controls
61 lines (49 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Programa pruebasRecursivas;
Variables
x : Entero;
Entero Funcion factor(dato : Entero) {
Si (dato == 0) Entonces {
Regresa(1);
}
Sino {
Regresa(dato * factor(dato - 1));
}
}
Entero Funcion fiboRecursivo(dato:Entero) {
Si (dato <= 1) Entonces {
Regresa(dato);
}
Sino {
Regresa (fiboRecursivo(dato - 1) + fiboRecursivo(dato - 2));
}
}
Entero Funcion fiboCiclico(tope : Entero)
Variables
num1, num2, suma, count : Entero;
{
num1 = 0;
num2 = 1;
suma = 1;
Desde (count = 1) Hasta tope Hacer{
suma = num1 + num2;
num1 = num2;
num2 = suma;
}
Regresa(suma);
}
Void Funcion decirHola(){
Escribir("I am Groot");
}
Principal(){
decirHola();
# PRUEBAS RECURSIVAS
Escribir("Dame el factorial de...");
Leer(x);
Escribir(factor(x));
Escribir("Dame el fibonacci recursivo de...");
Leer(x);
Escribir(fiboRecursivo(x));
Escribir("Dame el fibonacci ciclico de...");
Leer(x);
Escribir(fiboCiclico(x));
}