解题思路:前几道题的代码直接用,i从2开始,i替换为i*i,1替换-1,每次递减t的;最后输出1.0-t
注意事项:输出时是1.0-t的值
参考代码:
/* */ #include <cstdio> #include <algorithm> #include <iostream> using namespace std; int main(){ int n; cin>>n; double t=0.0; for(int i=2;i<=n;i++){ t-=-1.0/double(i*i); } printf("%.6lf",1.0-t); return 0; }
0.0分
0 人评分