Last active
August 29, 2015 14:00
-
-
Save iblue/11393688 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <stdio.h> | |
#include <math.h> | |
/* | |
* Compile and run: | |
* | |
* gcc -lm -march=native -O3 -o madelung madelung.c -lm && ./madelung | |
*/ | |
#define STEPS 100000 | |
int main(void) { | |
int i,j; | |
long double result=0.0d; | |
for(i=1;i<STEPS;i++) { | |
for(j=1;j<STEPS;j++) { | |
long double temp = ((long double)1.0d)/sqrt(pow((long double)i,2.0d) + pow((long double)j,2.0d)); | |
if((i+j)%2 == 0) { | |
result += temp; | |
} else { | |
result -= temp; | |
} | |
} | |
printf("%d/%d done\n", i, STEPS); | |
} | |
printf("%0.100f\n", (double)result); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment