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