File tree Expand file tree Collapse file tree
Fibonacci_series/C#/Davipb Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using System . Collections . Generic ;
2+
3+ namespace Fib
4+ {
5+ public static class Fibonacci
6+ {
7+ /// <summary>
8+ /// Generator method that calculates the Fibonacci sequence
9+ /// </summary>
10+ /// <returns>The fibonacci sequence</returns>
11+ public static IEnumerable < ulong > Sequence ( )
12+ {
13+ ulong a = 1 ;
14+ ulong b = 1 ;
15+
16+ yield return a ;
17+ yield return b ;
18+
19+ while ( true )
20+ {
21+ yield return a + b ;
22+
23+ ulong temp = a ;
24+ a = b ;
25+ b = temp ;
26+ a += b ;
27+ }
28+ }
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Text ;
5+ using System . Threading . Tasks ;
6+
7+ namespace Fib
8+ {
9+ public static class Fibonacci_test
10+ {
11+ static void Main ( string [ ] args )
12+ {
13+ Test ( ) ;
14+ Console . ReadKey ( ) ;
15+ }
16+
17+ public static void Test ( )
18+ {
19+ foreach ( var numb in Fibonacci . Sequence ( ) )
20+ {
21+ Console . WriteLine ( numb ) ;
22+
23+ if ( Console . ReadKey ( true ) . Key == ConsoleKey . Escape )
24+ break ;
25+ }
26+ }
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments