Advertisement
miroLLL

FibonacciNumbers

Sep 11th, 2015
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class FibonacciNumbers
  5. {
  6.     static void Main()
  7.     {
  8.         Console.Write("Length is: ");
  9.         long n = long.Parse(Console.ReadLine());
  10.         long firstNum = 0;
  11.         long secondNum = 1;
  12.         long thirdNum = 1;
  13.         if (n == 0)
  14.         {
  15.             Console.WriteLine("Sorry, counting starts from 1...");
  16.         }
  17.         if (n == 1)
  18.         {
  19.             Console.WriteLine(firstNum);
  20.         }
  21.         else
  22.         {
  23.             if ( n > 2)
  24.             {
  25.                 Console.WriteLine("{0} ", firstNum);
  26.                 Console.WriteLine("{0} ", secondNum);
  27.                 Console.WriteLine("{0} ", thirdNum);
  28.             }
  29.             for (int i = 0; i < n-3; i++)
  30.             {
  31.                 firstNum = secondNum;
  32.                 secondNum = thirdNum;
  33.                 thirdNum = firstNum + secondNum;
  34.                 Console.WriteLine("{0} ", thirdNum);
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement