#include<bits/stdc++.h> using namespace std; double dx = 1,sum = 0,x,y,dy; int main() { int n; cin >> n; //精确程度 for (int i = 1 ; i <= n ; i ++) { sum = 0; dx *= 0.1; printf("delta x = %llf ... sum = ",dx); for (x = dx ; x <= 1-dx ; x += dx) { y = sqrt(1-x*x); dy = -x/y*dx; sum += sqrt(dx*dx+dy*dy); // printf("%.5f %.5f %.5f\n",x,y,sum); } sum += 2*sqrt(dx*dx+dy*dy); printf("%lf\n",sum*4); } return 0; }
实际测试结果:
理论结果:
原文:https://www.cnblogs.com/YMY666/p/10827397.html