-
-
Save IneonInoodle/f59d55011f894b34ff03238487d2d449 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static IEnumberable<int> GenerateFibonacciNumbers(int n) | |
{ | |
List<int> myList = new List<int>(); | |
for (int i = 0, j = 0, k = 1; i < n; i++) | |
{ | |
yield return j; | |
int temp = j + k; | |
j = k; | |
k = temp; | |
} | |
return myList; | |
} | |
public static void Main(String[] args) | |
{ | |
foreach (int x in GenerateFibonacciNumbers(5)) | |
{ | |
Console.WriteLine(x); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment