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