Advertisement
diyanborisov

FibonacciNumbers

Nov 29th, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Numerics;
  7.  
  8.  
  9. class FibonacciNumbers
  10. {
  11.     static void Main()
  12.     {
  13.         int n = Int32.Parse(Console.ReadLine());
  14.         int[] fibonacci = new int[n];
  15.         if(n==1)
  16.         {
  17.             Console.WriteLine(0);
  18.         }
  19.         else
  20.         {
  21.             fibonacci[0] = 0;
  22.             fibonacci[1] = 1;
  23.             int first = 0;
  24.             int second = 1;
  25.             int third = 0;
  26.             for (int i = 2; i < n; i++)
  27.             {
  28.                 third = first + second;
  29.                 fibonacci[i] = third;
  30.                 first = second;
  31.                 second = third;
  32.             }
  33.             for (int i = 0; i < fibonacci.Length; i++)
  34.             {
  35.                 Console.Write(fibonacci[i]+" ");
  36.             }
  37.             Console.WriteLine();
  38.         }
  39.        
  40.  
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement