Skip to content

Instantly share code, notes, and snippets.

@ikr7
Created October 5, 2016 11:22
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 ikr7/898c2197977d2ee75dfecfa63e69a258 to your computer and use it in GitHub Desktop.
Save ikr7/898c2197977d2ee75dfecfa63e69a258 to your computer and use it in GitHub Desktop.
マンデルブロ集合(を定義する漸化式)を用いた円周率の近似
#include <stdio.h>
#include <math.h>
#define MAX_ITER 100000000
int N (long double c) {
long double z = 0.0;
for (int n = 0; n < MAX_ITER; n++) {
z = z * z + c;
if (z >= 2.0) {
return n + 1;
}
}
return 0;
}
int main () {
for (int i = 0; i < 16; i += 2) {
printf("%1.10Lf\n", N(0.25 + powl(10, -i)) / powl(10, i / 2));
}
}
@ikr7
Copy link
Author

ikr7 commented Oct 5, 2016

参考: https://www.youtube.com/watch?v=d0vY0CKYhPY

出力:

2.0000000000
3.0000000000
3.1200000000
3.1400000000
3.1414000000
3.1415700000
3.1415910000
3.1415920000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment