Last active
March 14, 2019 02:53
-
-
Save jdh8/fb59f7d7a4be6873241a8cc4b3d3b217 to your computer and use it in GitHub Desktop.
Fibonacci sequence from F(0) to F(100)
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> | |
static void print128(unsigned __int128 a) | |
{ | |
const unsigned long long base = 10000000000000000000; | |
if (a >> 64) | |
printf("%llu%0.19llu\n", (unsigned long long)(a / base), (unsigned long long)(a % base)); | |
else | |
printf("%llu\n", (unsigned long long)a); | |
} | |
int main() | |
{ | |
__int128 curr = 0; | |
__int128 next = 1; | |
for (int i = 0; i <= 100; ++i) { | |
printf("Fibonacci #%d: ", i); | |
print128(curr); | |
__int128 last = next; | |
next += curr; | |
curr = last; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment