计算1-1/2+1/3-1/4...+1/99-1/100的值
#include<stdio.h>
int main()
{
int j=2;
float term;
float sign=1;
float sum=1;
while(j<=100)
{
sign=-sign;
term=sign/j;
sum=sum+term;
j++;
}
printf("%f\n",sum);
return 0;
}
计算1-1/2+1/3-1/4...+1/99-1/100的值
#include<stdio.h>
int main()
{
int j=2;
float term;
float sign=1;
float sum=1;
while(j<=100)
{
sign=-sign;
term=sign/j;
sum=sum+term;
j++;
}
printf("%f\n",sum);
return 0;
}