File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Roadmap/06 - RECURSIVIDAD/c# Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments