Home > Back-end >  C language approximation for PI
C language approximation for PI

Time:12-06

# include "stdio.h"
Int main ()
{
Double=1 b, c, d, e=1, f, eps;
The scanf (" % le ", & amp; Eps);
Do {
If (eps> 1)
{
E=1;
break;
}
B +=2;
For (d=0, c=1, f=3; D<((b + 1)/2) - 1; D++, f +=2)
{
C *=(d + 1)/f;
}
E +=c;
} while (c>=(eps);
Printf (" %. 5 lf ", 2 * e);
}




Subject to code program, according to the type of PI approximation, until the last item is less than the given precision eps,

? 2
?
? PI
??=1 +
? 3
?
? 1!
?? +
? 3 x 5
?
? 2!
?? +
? 3 x 5 x 7
?
? 3!
?? +? +
? 3 x 5 x? * (2 * I + 1)
?
? i!
?? +?

Input format:
Precision eps given in the input in one line, you can use the following statement to read input:

The scanf (" % le ", & amp; Eps);
The output format:
In a row, according to the following format output PI approximation (5) after the decimal point:

PI=approximation
Input the sample:
1-5 e
The output sample:
PI=3.14158
Why I can't in pta submission
  • Related