Guest User

Untitled

a guest
Jan 19th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5. public List<int> Fibonacci(int limit)
  6.     {
  7.     int a = 0;
  8.     int b = 1;
  9.     boolean found=false;
  10.     List<int> forreturn = new List<int>();
  11.     while(!found)
  12.     {
  13.         int temp = a;
  14.         a = b;
  15.         b = temp + b;
  16.         a < limit ? forreturn.add(a) : found=true;     
  17.     }
  18.     return forreturn;
  19.     }
  20.  
  21. static void Main()
  22.     {
  23.     boolean success = false;
  24.     int limit = 0;
  25.     while(!success)
  26.     try {   limit = int.Parse(Console.Readline());
  27.         success=true;
  28.         }
  29.     Console.Writeline();
  30.         foreach( int i in Console.WriteLine(Fibonacci(limit)))
  31.     {
  32.      Console.Write(i," , ");
  33.     }
  34.     }
  35. }
Add Comment
Please, Sign In to add comment