Created
February 4, 2015 02:12
-
-
Save Wunkolo/f005f3abb5d5c5fe95a7 to your computer and use it in GitHub Desktop.
Pi Approximation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pi approximatization | |
//http://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80 | |
//Slow conversion... | |
#include <stdint.h> | |
#include <stdio.h> | |
int main() | |
{ | |
double result = 0; | |
for( size_t k = 1; k <= 1000000; k++ ) | |
{ | |
result += ((k & 1 ? 1.0 : -1.0) / double((k << 1) - 1)); | |
} | |
result *= 4; | |
printf("%.10lf\n", result); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment