Advertisement
Guest User

Fibonacci Numbers

a guest
Mar 21st, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2. class FibonacciNumbers
  3. {
  4.     static void Main()
  5.     {
  6.         int number = int.Parse(Console.ReadLine());
  7.         int first = 0;
  8.         int second = 1;
  9.         int result = 0;
  10.         if (number == 1 || number == 0)
  11.         {
  12.             Console.WriteLine(first);
  13.         }
  14.         else
  15.         {
  16.             Console.Write("{0} {1} ", first, second);
  17.             for (int i = 2; i < number; i++)
  18.             {
  19.                 result = first + second;
  20.                 first = second;
  21.                 second = result;
  22.                 if (i == number - 1)
  23.                 {
  24.                     Console.Write(result);
  25.                 }
  26.                 else
  27.                 {
  28.                     Console.Write(result + " ");
  29.                 }
  30.             }
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement