C++

jojoy 发表于 1年前 · 关联问题 π 值计算

include

include

using namespace std; int main() {

int s = 1; double n = 1.0, t = 1.0, pi = 0; while (fabs(t) > 1e-4) { pi = pi + t; n = n + 2; s = -s; t = s / n; } pi = 4 * pi; cout << pi;

}