Advertisement
remote87

Check if numbers are in Fibonacci range

Aug 11th, 2015
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace SomeFibonacciPrimes
  5. {
  6.     class SomeFibonacciPrimes
  7.     {
  8.         static void Main()
  9.         {
  10.             int first = 0;
  11.             int second = 1;
  12.             int third = 1;
  13.             List<int> fibnoList = new List<int>();
  14.             fibnoList.Add(first);
  15.             fibnoList.Add(second);
  16.             fibnoList.Add(third);
  17.             for (int i = 0; i < 50; i++)
  18.             {        
  19.                
  20.                 third = second;
  21.                 second = first + second;
  22.                 first = third;
  23.                 Console.WriteLine(first);
  24.                 fibnoList.Add(first);
  25.             }
  26.             for (int i = 0; i < 3; i++)
  27.             {
  28.                 Console.WriteLine("Enter a number to find if it's in Fibonacci range:");
  29.                 int number = int.Parse(Console.ReadLine());
  30.                     if (fibnoList.Contains(number))
  31.                     {
  32.                         Console.WriteLine("Your number is within the Fibonacci range.");
  33.                     }
  34.                     else
  35.                     {
  36.                         Console.WriteLine("Your number is NOT within the Fibonacci range");
  37.                     }
  38.             }          
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement