fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. double root5 = Math.Sqrt(5);
  8. double phi = (1 + root5) / 2;
  9.  
  10. int input;
  11. Console.Write("Enter a number : ");
  12. input = Convert.ToInt32(Console.ReadLine());
  13.  
  14. Console.Write("Fibonacci numbers to {0}: ", input);
  15.  
  16. int n=0;
  17. int Fn;
  18. do
  19. {
  20. Fn = (int)((Math.Pow(phi,n) - Math.Pow(-phi, -n)) / (2 * phi - 1 ));
  21. Console.Write("{0} ", Fn);
  22. ++n;
  23. } while(Fn < input);
  24. }
  25. }
  26.  
Success #stdin #stdout 0s 29664KB
stdin
21
stdout
Enter a number : Fibonacci numbers to 21: 0 1 1 2 3 5 8 13 21