Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- class FibonacciNumbers
- {
- static void Main()
- {
- Console.Write("Length is: ");
- long n = long.Parse(Console.ReadLine());
- long firstNum = 0;
- long secondNum = 1;
- long thirdNum = 1;
- if (n == 0)
- {
- Console.WriteLine("Sorry, counting starts from 1...");
- }
- if (n == 1)
- {
- Console.WriteLine(firstNum);
- }
- else
- {
- if ( n > 2)
- {
- Console.WriteLine("{0} ", firstNum);
- Console.WriteLine("{0} ", secondNum);
- Console.WriteLine("{0} ", thirdNum);
- }
- for (int i = 0; i < n-3; i++)
- {
- firstNum = secondNum;
- secondNum = thirdNum;
- thirdNum = firstNum + secondNum;
- Console.WriteLine("{0} ", thirdNum);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement