Created
April 27, 2020 12:33
-
-
Save Cogitri/aac8b51558afb99861a1a580e081c07a to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
#include <time.h> | |
unsigned long long fibo(unsigned long long f) | |
{ | |
unsigned long long nMinusTwo = 0; | |
unsigned long long nMinusOne = 1; | |
unsigned long long n = 0; | |
/* | |
Wenn f < 2, sprich 0 oder 1 ist, return f, da diese beiden Fibonaaci-Zahlen | |
sich etwas anders verhalten als der Rest. | |
*/ | |
if (f < 2) | |
{ | |
return f; | |
} | |
/* | |
Die Fibonacci-Zahl n ergibt sich aus: n F_n = F_n-2 F_n-1. Somit müssen wir also | |
jede Fibonacci-Zahl vor unserer Fibonacci-Zahl an Stelle `f` berechnen. | |
*/ | |
for (int i = 0; i < f; i++) | |
{ | |
/* F_n-2 */ | |
nMinusTwo = nMinusOne; | |
/* F_n-1 */ | |
nMinusOne = n; | |
/* Fibonacci Zahl an Stelle n */ | |
n = nMinusOne + nMinusTwo; | |
} | |
return n; | |
} | |
int main() | |
{ | |
clock_t tm1, tm2; | |
tm1 = clock(); | |
printf("Num: %ld\n", fibo(2999999999)); | |
tm2 = clock(); | |
printf("Dauer: %.2f Sekunden\n", (double)(tm2 - tm1) / CLOCKS_PER_SEC); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment