Skip to content

Instantly share code, notes, and snippets.

@SergiyOsadchyy
Created June 23, 2018 15:44
Show Gist options
  • Save SergiyOsadchyy/a84cb52e2199c3e95cbd12b1ea6241c4 to your computer and use it in GitHub Desktop.
Save SergiyOsadchyy/a84cb52e2199c3e95cbd12b1ea6241c4 to your computer and use it in GitHub Desktop.
C# Fibonacci
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