题解 | #牛牛学数列3#
牛牛学数列3
https://www.nowcoder.com/practice/f65c726d081c4160a9356eabf0dc21d9
#include <stdio.h> #include <math.h> int main() { int n; scanf("%d",&n); long double sum = 0.0; for(int i = 1;i <= n;i++){ sum = sum + (1.0 / (pow(-1,i-1) * i)); // (1-3+5-...((-1)^(n-1))*(2n-1)) 可以转变为 -1的n-1次方乘以n; } printf("%.3Lf",sum); }