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