codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
/* Print the value of pi */ #include <stdio.h> #include <stdlib.h> #include <math.h> #define DECIMAL_ACCURACY 1E-6 /** * Using Basel problem (sum of series of inverted square) * http://en.wikipedia.org/wiki/Basel_problem */ int main() { double fac = 0.0; double val = 0.0; int x = 0; do { ++x; fac = 1.0 / x / x; val += fac; } while(fac > DECIMAL_ACCURACY); printf( "Value of pi is: %g\n", sqrt(6.0 * val) ); return 0; }
Private
[
?
]
Run code
Submit