http://www.iwriteiam.nl/SigProgC.html
Calculating Pi in 2 lines by Dik T. Winter
The following 160 character C program, written by Dik T. Winter at CWI, computes pi to 800 decimal digits.
#include<stdio.h>
int a=10000,b,c=2800,d,e,f[2801],g;main(){for(;b-c;)f[b++]=a/5;for(;d=0,g=c*2;c
-=14,printf("%.4d",e+d/a),e=d%a)for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);}
#include<stdio.h>
a[52514],b,c=52514,d,e,f=1e4,g,h;main(){for(;b=c-=14;h=printf("%04d",
e+d/f))for(e=d%=f;g=--b*2;d/=g)d=d*b+f*(h?a[b]:f/5),a[b]=d%--g;}
For some background information, read Unbounded Spigot Algorithms for the Digits of Pi. (And even shorter.)
'c·c++ > c 프로그래밍' 카테고리의 다른 글
c/c++ 책소개 (0) | 2013.05.20 |
---|---|
이분검색 (0) | 2013.05.14 |
Dijkstra's algorithm (0) | 2013.05.11 |
연결리스트를 이용한 병합정렬(천만개의 정수자료 정렬) (0) | 2013.05.11 |
%의 활용 (0) | 2013.05.08 |