算法[ma教教主]说的很明白了,直接贴代码了。
C:
#include
long a = 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);
}
VB:
Dim sum As Double, t As Double
Dim N As Integer
N = 6 'N是计算精度,越大越精确,但运算越慢
sum = 0: t = 1
Do
sum = sum + (-1) ^ (t + 1) / (2 * t - 1)
t = t + 1
Loop Until Abs((-1) ^ (t + 1) / (2 * t - 1)) < 10 ^ (-N)
Magbox 4 * sum
BAT:
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set pi=400000000
set t=0
set p=3
set times=0
set det=-1
set p1=-3
:loop
set /a
t=400000000/p1
set /a pi=pi+t
set /a p=p+2
set /a det=det*-1
set /a
p1=p*det
set /a times=times+1
if %times% geq 4000 goto ex :: 可以写成 if %times% geq 40000 goto ex
goto loop
:ex
set /a pi=pi%%100000000
echo 结果 3.%pi%
pause