题解 | #牛牛学数列3#
牛牛学数列3
https://www.nowcoder.com/practice/f65c726d081c4160a9356eabf0dc21d9
#include<stdio.h>
int main()
{
int n,i;
double sum;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2==0)//当为偶数时,则输出负值
sum-=1.0/i;
else
sum+=1.0/i;
}//累加输出sum
printf("%.3lf\n",sum);
return 0;
}