Skip to content

Commit 9543705

Browse files
authored
Merge pull request mouredev#7339 from devcherry1/patch-11
#6 - C#
2 parents b1a5d03 + e7d9acb commit 9543705

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
3+
class Program
4+
{
5+
static void Main()
6+
{
7+
contador(100);
8+
Console.WriteLine("Indique la posicion en la serie Fibonacci: ");
9+
int serie;
10+
int.TryParse(Console.ReadLine(), out serie);
11+
Console.WriteLine(Extra.Fibonacci(serie));
12+
int factor;
13+
int.TryParse(Console.ReadLine(), out factor);
14+
Console.WriteLine(Extra.Factorial(factor));
15+
}
16+
static void contador(int limite)
17+
{
18+
if (limite == 0)
19+
{
20+
Console.WriteLine(limite);
21+
return;
22+
}
23+
Console.WriteLine(limite);
24+
contador(limite - 1);
25+
}
26+
}
27+
class Extra
28+
{
29+
public static int Fibonacci(int posicion)
30+
{
31+
// Casos base
32+
if (posicion == 0) return 0;
33+
if (posicion == 1) return 1;
34+
35+
// Caso recursivo
36+
return Fibonacci(posicion - 1) + Fibonacci(posicion - 2);
37+
}
38+
public static int Factorial(int numero)
39+
{
40+
if (numero == 0) return 1;
41+
42+
return numero * Factorial(numero - 1);
43+
}
44+
}

0 commit comments

Comments
 (0)