Skip to content

Instantly share code, notes, and snippets.

@jdh8
Last active March 14, 2019 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdh8/fb59f7d7a4be6873241a8cc4b3d3b217 to your computer and use it in GitHub Desktop.
Save jdh8/fb59f7d7a4be6873241a8cc4b3d3b217 to your computer and use it in GitHub Desktop.
Fibonacci sequence from F(0) to F(100)
#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