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1-x^2}}dx}

#include <math.h>
#include <stdio.h>

int main()
{
double delta_x = 1e-11;
double s = 0;
unsigned long long i = 0;
for (double x = 0; x <= 1; x+=delta_x) {
double delta_s = sqrt(1.0/(1.0-x*x)) * delta_x;
s += delta_s;

if (0 == i % 10000000000) {
printf("current x:%lf\n", x);
}
i ++;
}

return 0;
}

4 篇文章10 人订阅

0 条评论

87880

26120

973120

30990

797150

14400

12930

14210

38590