程序代码:
#include <stdio.h> int main() { double dx = 1, dy = 1, n = 0; double d = 1, sum = 1; while (d >= 1e-6) { dx *= ++n; dy *= (2 * n + 1); d = dx / dy; sum += d; } sum *= 2; printf("%lf", sum); return 0; }
#include <stdio.h> int main() { double dx = 1, dy = 1, n = 0; double d = 1, sum = 1; while (d >= 1e-6) { dx *= ++n; dy *= (2 * n + 1); d = dx / dy; sum += d; } sum *= 2; printf("%lf", sum); return 0; }