SHARE
TWEET

FibonacciNumbers

Stann Mar 29th, 2014 147 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Numerics;
  3. class FibonacciNumbers
  4. {
  5.     static void Main()
  6.     {
  7.         //Define a method Fib(n) that calculates the nth Fibonacci number.
  8.         int n = int.Parse(Console.ReadLine());
  9.          Fib(n);
  10.     }
  11.     static void Fib(int n)
  12.     {
  13.         BigInteger numOne = 0;
  14.         BigInteger numTwo = 1;
  15.         BigInteger nextNum = 0;
  16.         for (int i = 1; i <= n-2; i++)
  17.         {
  18.             nextNum = numOne + numTwo;
  19.             numOne = numTwo;
  20.             numTwo = nextNum;
  21.         }
  22.         Console.WriteLine(nextNum);
  23.     }
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top