题解 | #牛牛学数列3#
牛牛学数列3
https://www.nowcoder.com/practice/f65c726d081c4160a9356eabf0dc21d9
#include <stdio.h> int main() { int n; double sum1=0; int sum2=0; scanf("%d",&n); int flag=1; for(int i=1;i<=n;i++) { sum2=sum2+flag*(2*i-1); sum1=sum1+(1.0/sum2); flag=-flag; } printf("%.3lf",sum1); return 0; }