批处理bat递归计算N!的实现代码
核心代码:
@echooff ::代码来自网友:liangbch setlocalenabledelayedexpansion echoTocalculaten^^! set/pnn=n=? set/a"buff_1=1,rad=10000,len=1" for/l%%iin(1,1,%nn%)do( set/acc=0 for/l%%jin(1,1,!len!)do( set/a"tt=buff_%%j*%%i+!cc!" set/a"buff_%%j=!tt!%%!rad!,cc=!tt!/!rad!" ) if!cc!gtr0( set/alen+=1 set/abuff_!len!=!cc! ) ) set/pxx=n^^!=<nul set/att=buff_%len% set/pxx=!tt!<nul set/alen-=1 for/l%%iin(%len%,-1,1)do( set/att=buff_%%i if!tt!lss1000settt=00000!tt! set/pxx=!tt:~-4!<nul ) echo. pause
双击输入数字即可。