PI code does this calculation right? ?

Users questions: longa=10000,b,c=2800,d,e,f[2801],g;main(){for(;b-c;)f[b++]=a*5;for(;d=0,g=c*2;c-=14,printf( %.4d ,e+ d * a), e = d% a) for (b = c; d + = f [b] * a, f [b] = d% ** g, d *= g **,** b; d * = b);)
Experts answer: This is a very powerful online popular procedure for the calculation of PI, of course, right. Mathematicians have studied numerous Method to calculate the PI, the formula used in this procedure is as follows: 123kpi = 2 +**-*( 2 +**-*( 2 +**-*( 2 +...( 2 +*****( 2 +...))...))) 3572k +1 following a clear procedure of how this formula . Let's check whether this formula: Pi Formula verification process: # include "stdio.h" voidmain () (floatpi = 2; inti; for (i = 100; i = 1; i **) pi = pi * (float ) i * (2 * i +1) +2; printf ("% f * n", pi); getchar ();) The above result of this process is 3.141593. We put the above procedure for the formal analysis process, we need to look to start the program a. We can see that process Procedures are used for a loop to complete the calculation, although this process can be made short, but hard to read. According to the order for the cycle to run, we can expand it into the following while loop of the program: for the procedure after converting while inta = 1000 +f[b]*a;g**;f[b]=d%g;d=d*g;g**;b**;if(b==0)break;d=d*b;}c=c-14;printf( %.4d ,e+d*a);e=d%a;}} for([1 ]; [2]; [3]) ([4];) running order is [1], [2], [4], [3]. If you have a comma operator, for example: d = 0, g = c * 2, the first run d = 0, and then run the g = c * 2, and the end result is the value of the last expression, which is the In the c * 2. After we started following the procedures for the analysis: To calculate the infinite precision of the PI, Women need Shangshu numerous times to run the iterative formula, and in which each score is completely accurate, both in the computer can not be realized in nature . So basically iterative thinking is often enough , And each fraction is also precise enough, so we can calculate the first n bits PI. This process calculated above 800, a total of iterative iterative formula 2800 times. inta = 10000, b, c = 2800, d, e, f [2801], g; this sentence in 2800 on Is the number of iterations. As the float or double precision is not enough, so the program using the integer type (actually a long integer), sub-operations (4 for each calculation). We can see the output statement printf ("% .4 d", e + d * a); which is .4% The calculated 4-bit output, we see a fall in c 14 (c = c-14;), and c of the initial size of 2800, so a total of 200 on the sub-section operation, and each output 4, So total output of 800. The use of integer operations, it is necessary to take a series Number of factors in this process is 1000, that is, the formula is as follows: 123k1000 * pi = 2k +**-*( 2k +**-*( 2k +**-*( 2k +...( 2k +***** (2k +...))...))) 3572k +1 this In the 2k that 2000, that is, f [2801] After initializing the array of data, a = 10000, a * 5 = 2000, so the following procedure to each element f in the assignment to 2000: for (i = 0; ic; i + +) f [i] = a * 5; you can
  • This information provided by the users.Thanks!