#include "stdio.h"
main()
{
float sum,
i=1,j,t=1;
do
{j=t/i;i++;
t=t*(-1);
sum+= j;
}while (sum>0.0001);
printf("1-1/2+1/3-1/4+ ... +-1/n = %lf", sum);
}
什么地方错了
#include "stdio.h"
main()
{
float sum=0,
i=1,j,t=1;
do
{j=t/i;i++;
t=-t;
sum+= j;
}while (i<=10000);
printf("1-1/2+1/3-1/4+ ... +-1/%.0f = %lf",i, sum);
}