首页 > 其他分享 >例2.4 求1-1/2+1/3-1/4+···+1/99-1/100

例2.4 求1-1/2+1/3-1/4+···+1/99-1/100

时间:2022-09-29 23:31:21浏览次数:38  
标签:term int sum sign 99 deno 100 2.0 2.4

 

#include<stdio.h>

int main()

{

 int sign = 1;

 double deno = 2.0, sum = 1.0, term;//deno分母,sum多项式,term分式

 while (deno <= 100)

 {

  sign = -sign;

  term = sign / deno;

  sum = sum + term;

  deno = deno + 1;

 }

 for(int deno=1;deno<=100;deno++){

  sign = -sign;

  term = sign / deno;

  sum += term;  

 }

 printf("%f\n",sum);

 return 0;

}

标签:term,int,sum,sign,99,deno,100,2.0,2.4
From: https://blog.51cto.com/u_15804165/5724455

相关文章