Skip to content

Instantly share code, notes, and snippets.

@CodingBobby
Created March 17, 2018 22:42
Show Gist options
  • Save CodingBobby/68a5900d97b43e7b34278abc06b4e6bd to your computer and use it in GitHub Desktop.
Save CodingBobby/68a5900d97b43e7b34278abc06b4e6bd to your computer and use it in GitHub Desktop.
calculates first 800 digits of pi
#include <stdio.h>
int main() {
int r[2800 + 1];
int i, k;
int b, d;
int c = 0;
for (i = 0; i < 2800; i++) {
r[i] = 2000;
}
for (k = 2800; k > 0; k -= 14) {
d = 0;
i = k;
for (;;) {
d += r[i] * 10000;
b = 2 * i - 1;
r[i] = d % b;
d /= b;
i--;
if (i == 0) break;
d *= i;
}
printf("%.4d", c + d / 10000);
c = d % 10000;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment