Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Numerics;
- class FibonacciNumbers
- {
- static void Main ()
- {
- Console.Write("Please, enter a whole positive number for N = ");
- string numberStr = Console.ReadLine();
- int numN = int.Parse(numberStr);
- if (numN < 1 || numN > 100000)
- {
- Console.WriteLine("Error - The number {0} is out of range !!!");
- }
- else
- {
- checked
- {
- BigInteger fibonacciFirst = 1;
- BigInteger fibonacciSecond = 1;
- Console.WriteLine("The First N members of Fibonacci Numbers are:");
- if (numN == 1)
- {
- Console.WriteLine("{0}, ", fibonacciFirst);
- }
- else
- {
- Console.Write("{0}, {1}, ", fibonacciFirst, fibonacciSecond);
- BigInteger fibonacciN = 1;
- for (int i = 3; i <= numN; i++)
- {
- fibonacciN = fibonacciFirst + fibonacciSecond;
- Console.Write("{0}, ", fibonacciN);
- fibonacciFirst = fibonacciSecond;
- fibonacciSecond = fibonacciN;
- }
- }
- }
- }
- Console.ReadLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement