c语言 编写一个程序 1-1/2+1/3-1/4+1/5……-1/99+1/100用while语句!

如题所述

#include<stdio.h>
int main()
{int i=1;
 float s=0;
 while(i<101)
 {if(i%2)s+=1.0/i;
    else s-=1.0/i;
  i++;  
 } 
 printf("%f\n",s);  
 return 0;
}

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答