Advertisement
VasilKotsev

ListFibonacci

Jan 19th, 2019
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. namespace SandBox
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.  
  6.     public class EntryPoint
  7.     {
  8.         public static void Main()
  9.         {
  10.             int number = int.Parse(Console.ReadLine());
  11.  
  12.             List<long> sequence = new List<long>() { 1L, 1L };
  13.  
  14.             string output = string.Empty;
  15.  
  16.             if (number == 0)
  17.             {
  18.                 output = "0";
  19.             }
  20.  
  21.             else if (number == 1)
  22.             {
  23.                 output = "1";
  24.             }
  25.  
  26.             else
  27.             {
  28.  
  29.                 for (int i = 2; i < number; i++)
  30.                 {
  31.                     long nextNumberInSequence = sequence[i - 1] + sequence[i - 2];
  32.                     sequence.Add(nextNumberInSequence);
  33.                 }
  34.  
  35.                 output = string.Join(" ", sequence);
  36.             }
  37.  
  38.             Console.WriteLine(output);
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement