本帖最后由 plp626 于 2014-5-16 23:11 编辑
直接双击:默认计算100位,
命令行下:第一个参数(正整数)为计算圆周率的位数
-
- @echo off&title 计算圆周率 by plp626
- setlocal enabledelayedexpansion
- if %1.==. (set c=100) else set/a c=%1
- set/a c=(c*100/3)+70,cc=c/10,n=cc
- for /l %%a in (1 1 %cc%)do set/a f_%%a=2000
- for /l %%a in (%c% -132 100)do (set/a n=%%a/10,m=2*n-1
- set/a "d=f_!n!*10000,f_!n!=d%%m,d=d/m,n-=1"
- for /l %%b in (!n! -1 1)do (set/a n=%%b,m=2*n-1
- set/a "d=d*n+f_!n!*10000,f_!n!=d%%m,d=d/m,n-=1"
- )
- set/a "an=e+d/10000,e=d%%10000"
- if !an! lss 1000 set an=000!an!
- set/p=!an:~-4!<nul
- )
- echo\&echo/&set/p=数学爱好者加我QQ:275928264,验证号:plp626
复制代码
所用公式:
pi=2*1+2*1!/3!!+2*2!/5!!+2*3!/7!!+...+2*k!/(2*k+1)!!+...
|