Created
July 4, 2018 01:31
-
-
Save ProblemaResolt/716d7a5ed466e72cd80e1edf1cc2e5b9 to your computer and use it in GitHub Desktop.
fibonatch 数列 C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Stopwatch watch = new Stopwatch(); | |
watch.Start(); | |
for (int i = 0; i < 100000; i++) { | |
fib(50); | |
} | |
watch.Stop(); | |
Console.WriteLine("time" + watch.Elapsed); | |
Console.WriteLine(fib(50)); | |
Console.Read(); | |
} | |
static UInt64 fib(int n) | |
{ | |
UInt64 fib01,fib02; | |
fib01 = 0; | |
fib02 = 1; | |
for (int i = 1; i < n; i++) | |
{ | |
UInt64 a = fib01 + fib02; | |
fib01 = fib02; | |
fib02 = a; | |
} | |
return fib02; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment