coasterka

#4FibonacciNumbers

Mar 19th, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using System;
  2.  
  3. class FibonacciNumbers
  4. {
  5.     static void Main()
  6.     {
  7.         Console.WriteLine("How many numbers of the Fibonacci sequence would you like me to print?");
  8.         int count = int.Parse(Console.ReadLine());
  9.         for (int i = 0; i < count; i++)
  10.         {
  11.             Console.Write(Fibonacci(i) + " ");            
  12.         }
  13.         Console.WriteLine();
  14.         Console.ReadLine();
  15.  
  16.     }
  17.     public static int Fibonacci(int numbers)
  18.     {
  19.         int a = 0;
  20.         int b = 1;
  21.         for (int i = 0; i < numbers; i++)
  22.         {
  23.             int temp = a;
  24.             a = b;
  25.             b = temp + b;
  26.         }
  27.         return a;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment