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