Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static ulong Fibonacci(int n)
- {
- ulong a = 0;
- ulong b = 1;
- // In N steps compute Fibonacci sequence iteratively.
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
- for (int i = 0; i < n; i++)
- {
- ulong temp = a;
- a = b;
- b = temp + b;
- }
- stopWatch.Stop();
- // Get the elapsed time as a TimeSpan value.
- TimeSpan ts = stopWatch.Elapsed;
- string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
- ts.Hours, ts.Minutes, ts.Seconds,
- ts.Milliseconds / 10);
- //Console.WriteLine("Elapsed time:" + elapsedTime);
- return a;
- }
- static void Main(string[] args)
- {
- var i = 95;
- Console.WriteLine(Fibonacci(i) + ": " + i);
- Console.Read();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement