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