用C语言编程:求1-1/2+1/3-1/4+1/5-1/6+…+1/99-1/100+…的值…

如题所述

#include<stdio.h>
int main()
{int i=1,n;
 float s=0;
 scanf("%d",&n);
 while(i<=n)
 {if(i%2)s+=1.0/i;
    else s-=1.0/i;
  i++;  
 } 
 printf("%f\n",s);  
 return 0;
}
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答