1-1/2+1/3-1/4+……+1/99-1/100
S1: sigh=1
S2: sum=1
S3: deno=2
S4: sigh=(-1)×sigh
S5: term= sigh×(1/deno )
S6: term=sum+term
S7: deno= deno +1
S8:若deno≤100,返回S4;否则,结束。
每句话的意思!~~
快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快
参考答案:上面的算法,如果用C来做,程序应该是下面的代码:
main()
{
int i;
float sum=1,sign;
for(i = 2; i <= 100; i++)
{
sign = -1.0 / i;
sum += sign;
}
printf("the summation is %f\n",sum);
getch();
}