早期我们用来入门学习的方法:
- <span style="font-size:14px;"><strong style="background-color: rgb(255, 255, 102);">#include <stdio.h>
- int main ()
- {
- int sign = 1;
- double deno = 2.0,sum = 1.0,term;
- while(deno <= 100)
- {
- sign = -sign;
- term = sign/deno;
- sum = sum + term;
- deno = deno+1;
- }
- printf("the sum is %f\n",sum);
- return 0;
- }</strong></span>
现在我们可以在变量名和操作符上做一些改变,使程序看起来简便一点
- <span style="font-size:14px;"><strong style="background-color: rgb(255, 255, 102);">#include <stdio.h>
- int main ()
- {
- int i = 1;
- double j;
- double sum = 1;
- for(j=2; j<=100; j++)
- {
- i = -i;
- sum += i/j;
- }
- printf("the sum is %f\n",sum);
- return 0;
- }</strong></span>