Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1.  public static ulong Fibonacci(int n)
  2.         {
  3.             ulong a = 0;
  4.             ulong b = 1;
  5.             // In N steps compute Fibonacci sequence iteratively.
  6.             Stopwatch stopWatch = new Stopwatch();
  7.             stopWatch.Start();
  8.             for (int i = 0; i < n; i++)
  9.             {
  10.                 ulong temp = a;
  11.                 a = b;
  12.                 b = temp + b;
  13.             }
  14.             stopWatch.Stop();
  15.             // Get the elapsed time as a TimeSpan value.
  16.             TimeSpan ts = stopWatch.Elapsed;
  17.             string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
  18.                 ts.Hours, ts.Minutes, ts.Seconds,
  19.                 ts.Milliseconds / 10);
  20.             //Console.WriteLine("Elapsed time:" + elapsedTime);
  21.             return a;
  22.         }
  23.         static void Main(string[] args)
  24.         {
  25.             var i = 95;
  26.             Console.WriteLine(Fibonacci(i) + ":   " + i);
  27.             Console.Read();
  28.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement