forked from idg10/prog-cs-8-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
46 lines (41 loc) · 991 Bytes
/
Program.cs
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
using System;
using System.Collections.Generic;
using System.Numerics;
namespace ImplementingSequences
{
class Program
{
public static IEnumerable<int> Countdown(int start, int end)
{
for (int i = start; i >= end; --i)
{
yield return i;
}
}
private static void Main(string[] args)
{
foreach (int i in Countdown(5, 1))
{
Console.WriteLine(i);
}
}
public static IEnumerable<int> ThreeNumbers()
{
yield return 1;
yield return 2;
yield return 3;
}
public static IEnumerable<BigInteger> Fibonacci()
{
BigInteger v1 = 1;
BigInteger v2 = 1;
while (true)
{
yield return v1;
var tmp = v2;
v2 = v1 + v2;
v1 = tmp;
}
}
}
}