This is my code
# include & lt; Stdio. H>
# include & lt; Math. H>
Int main ()
{
Double eps, I=1, sum=0;
Int flag=1;
Lf the scanf (" % ", & amp; Eps);
Do
{
The sum +=I;
Flag=- flag;
I=flag/(I + 3);
} while (fabs (I) & gt; Eps);
Printf (" sum=%. 6 lf ", sum);
return 0;
}
CodePudding user response:
Fyi:# include & lt; Stdio. H>
# include & lt; Math. H>
Int main ()
{
Double t, eps, I=1, sum=1;
Int flag=1;
Lf the scanf (" % ", & amp; Eps);
Do
{
I=I + 3;
Flag=- flag;
T=1.0 * flag/I;
Sum=sum + t;
} while (fabs (t) & gt; Eps);
Printf (" sum=%. 6 lf ", sum);
return 0;
}
CodePudding user response:
flag * 1.0/(I + 3)
Ensure that the operation is floating point calculations, do not add the operation according to integer division, get the integer value