Created
June 23, 2018 15:44
-
-
Save SergiyOsadchyy/a84cb52e2199c3e95cbd12b1ea6241c4 to your computer and use it in GitHub Desktop.
C# Fibonacci
This file contains hidden or 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
using System; | |
namespace Test_2018_05_30 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Напишите функцию fib(n), которая виводить 100 парних чисел Фибоначчи. | |
Fib(100); | |
} | |
static void Fib(int n) | |
{ | |
ulong x, y, z; | |
int k; | |
for (x = 1, y = 1, z = x + y, k = 0; k < n; x = y, y = z, z = x+y) | |
{ | |
if (MyCheck(x)) | |
{ | |
Console.WriteLine("Fib # " + k + " is " + x); | |
k++; | |
} | |
} | |
} | |
static bool MyCheck(ulong x) | |
{ | |
if (x%2 == 0) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment