Advertisement
Stann

FibonacciNumbers

Mar 29th, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.55 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement