题目:编程计算 s = 1 - 1 / 2 + 1 / 3 - 1 / 4 + 1 / 5 - 1 / 6 + … + 1 / n
#include <stdio.h>
int main()
{
double s = 0, sign = 0;
int i, n;
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
if (i % 2 == 0) sign = -i;
else sign = i;
s = s + 1 / sign;
}
printf("%lf", s);
return 0;
}