1、批处理开平方批处理如何开平方批处理开平方,网上已有很多方法。但都存在一个问题:精确位数低,还有计算错误。甚至有的计算还很慢。本批处理程序算法能在较短时间内计算到较大的位数,实现了批处理开方的更高程度。以后会有更新:1.对算法进行优化:四百位以内平均十秒一位。 而非像现在需要十分钟。2.扩大被开方数范围:支持小数,且被开方数 数字个数(含小数点)从10扩大到2147483640。(注:未更新前仅支持1627396281及以内,刚好10位数)敬请期待!另外,不知道如何将以下代码做成bat程序的请XX一下:如何制作bat注意,部分计算器对最后一位进行了四舍五入,本程序可能会与计算器的最后一位相差1。
2、这不是本程序的错误。不相信本程序计算能力的的计算根号2,XX搜索:根号2 1000位 即可查到,可与本程序计算结果对比。代码中 大号 红色 加粗 加下划线 字仅为显示进度,为缩短计算时间可删除。可节省不少时间。代码如下:(注意别复制到结尾,代码部分包含两个程序)echo offtitle 计算整数平方根的值color f0PUSHD %dp0cd /d %dp0setlocal enabledelayedexpansionclsecho -echo 计算整数平方根的值echo -:startecho.&echo 请输入被开方数(仅限整数),然后按回车键:echo (被开方数最高为1627396
3、281,超出范围,会计算出错)set number=set /p number=goto next:nextclsif %number%= goto startset /a temp=%number%+0if not %temp%=%number% goto error_aif not %number% geq 0 goto error_bif %number% geq 1627396282 goto error_cgoto then:thenclsecho.&echo 请输入精确位数,然后按回车键:echo (指精确到小数点后第几位)echo (该程序不会对最后一位进行四舍五入)echo (
4、精确位数最高为238609294,超出范围,会计算出错)echo (对于结果为整数的,程序会舍去小数部分)set bit=set /p bit=goto other:otherclsif %bit%= goto thenset /a temp=%bit%+0if not %bit%=%temp% goto error_dif not %bit% geq 0 goto error_dif %bit% geq 238609295 goto error_eset start=yesgoto main:error_aclscolor fcecho 错误:输入的被开方数不是整数,请重新输入!echo 其
5、绝对值不得超过批处理支持的最大值(2147483647)!echo 请不要在整数前加上正号(+)或多余的零!echo.&echo 按任意键继续:&pausenulcolor f0clsgoto start:error_bclscolor fcecho 错误:平方根中被开方数不能小于0,请重新输入!echo.&echo 按任意键继续:&pausenulcolor f0clsgoto start:error_cclscolor fcecho 错误:被开方数不能大于1627396281,请重新输入!echo.&echo 按任意键继续:&pausenulcolor f0clsgoto start:er
6、ror_dclscolor fcecho 错误:输入的精确位数不是正整数,请重新输入!echo 其绝对值不得超过批处理支持的最大值(2147483647)!echo 请不要在整数前加上正号(+)或多余的零!echo.&echo 按任意键继续:&pausenulcolor f0clsgoto then:error_eclscolor fcecho 错误:精确位数不能大于238609294,请重新输入!echo.&echo 按任意键继续:&pausenulcolor f0clsgoto then:mainclsecho.&echo 已经开始计算。echo 每计算一位,都会对结果更新!echo 越往
7、后计算,结果显示越慢!请耐心等待本程序计算完成。echo.&echo 被开方数:%number%if not %start%=yes (set /a num+=1set /a tga=!num!-%allbit%-1set /a temp=!tga!%4if not !tga!=1 (if !temp!=1 (set nun=%nun% %main:-1%) else (set nun=%nun%main:-1%) else (set nun=%nun%main:-1%)set /a temp=%tga%+1if !temp!=%bit% goto endecho.&echo 计算结果(未对其
8、结果进行四舍五入):echo.&echo %nun%goto js) else (echo.&echo 请稍候goto temp):tempset u=0set tga=0call :stringlenth %number% numset /a allbit=(%num%+1)/2set num=%allbit%set tgb=%num%set /a num+=1for /l %i in (0 1 %num%) do set js%i=0if %allbit%=1 (set kfmain=js1call :kfmain) else (for /l %i in (%tgb% -1 1) do (
9、set u=0set kfmain=js%icall :kfmainset js%i=!temp!)set temp=for /l %i in (%tgb% -1 1) do (set temp=!temp!js%i!)set all=%temp%set /a temp=%all%*%all%if %temp%=%number% (set bit=0set nun=%all%goto end)if %bit%=0 (set nun=%all%goto end)set main=%all%.set nun=%all%.set start=nogoto js:jsset nmn=%main:.=%
10、set /a tgb=%num%-1set kfmain=js0if %tgb%=1 (set js1=%nmn%) else (for /l %i in (%tgb% -1 1) do (set temp=!nmn:-%i!set js%i=!temp:0,1!)set js%num%=0set u=0call :kfmainset main=%main%temp%goto main:endclsecho.&echo 计算完毕!echo.&echo 被开方数:%number%echo.&echo 计算结果(未对其结果进行四舍五入):echo !nun!echo.&echo 按任意键继续:&p
11、ausenulclsecho 请选择接下来的操作。echo -echo 0:退出echo 1:返回重新计算echo 2:将结果保存至桌面。echo -set choice=set /p choice=请输入操作序号,然后按回车键:if %choice%=0 exit /bif %choice%=1 (clsgoto start)if %choice%=2 goto exit_onegoto end:exit_oneif %bit%=0 (set temp=(保留整数)) else (set temp=(精确到小数点后第%bit%位))cd /d %UserProfile%desktopif e
12、xist %number%的平方根的结果%temp%.txt (takeown %number%的平方根的结果%temp%.txtdel /f /s /q %number%的平方根的结果%temp%.txt)echo %number%的平方根的结果:%number%的平方根的结果%temp%.txtecho %temp%:%number%的平方根的结果%temp%.txtecho (未对其结果进行四舍五入):%number%的平方根的结果%temp%.txtecho %nun%number%的平方根的结果%temp%.txtgoto exit:exitclsecho.&echo 保存完毕。ec
13、ho 请选择接下来的操作。echo -echo 0:退出echo 1:返回重新计算echo 2:打开保存到的文件并退出echo -set choice=set /p choice=请输入操作序号,然后按回车键:if %choice%=0 exit /bif %choice%=1 (clsgoto start)if %choice%=2 (start /d %windir% notepad.exe %UserProfile%desktop%number%的平方根的结果%temp%.txtexit /b)goto exit:kfmainset /a u+=1if %er%=2m (set %kfm
14、ain%=1goto jsmain)if %er%=5m (set %kfmain%=2goto jsmain)if %er%=4m (set %kfmain%=3goto jsmain)if %er%=2l (set %kfmain%=4goto jsmain)if %u%=1 (set %kfmain%=5goto jsmain)if %er%=7m (set %kfmain%=6goto jsmain)if %er%=5l (set %kfmain%=7goto jsmain)if %er%=9m (set %kfmain%=8goto jsmain)if %er%=7l (set %k
15、fmain%=9goto jsmain)if %er%=1m set temp=0if %er%=1l set temp=1if %er%=3m set temp=2if %er%=3l set temp=3if %er%=4l set temp=4if %er%=6m set temp=5if %er%=6l set temp=6if %er%=8m set temp=7if %er%=8l set temp=8if %er%=9l set temp=9goto :eof:jsmainset tgc=0set /a tgd=%num%*2-1for /l %i in (%tgd% -1 0)
16、 do set dg%i=0for /l %i in (0 1 %tgb%) do (for /l %r in (0 1 %num%) do (set /a i=%i+%rset /a temp=!js%i!*!js%r!+!tgc!set /a dg!i!+=!temp!%10set /a tgc=!temp!/10)set tgc=0if %tga% geq 50 (if %tga% geq 100 (set /p=nulset /p=总进度:%u%(最少3,最多4),副进度:%i(共%tgb%) nul) else (set /p=nulset /p=总进度:%u%(最少3,最多4) n
17、ulclsgoto start)if not %bit% geq 0 (clscolor fcecho 错误:输入的精确位数不是正整数,请重新输入!echo.&echo 按任意键继续:&pausenulclsgoto start)if not %bit% leq 238609294 (clscolor fcecho 错误:输入的精确位数不能大于238609294,请重新输入!echo.&echo 按任意键继续:&pausenulclsgoto start)goto start_ct:start_ct:可在下面保存进度:例:已算出结果为1.4142 1356:则可改为set nun=1.4142
18、 1356。注意小数点后四位一个英文状态下的空格,:但末尾不得有空格。(例:正确:1.4142,错误:1.4142 ):清除进度,改为set nun=1.。1.不能丢!set nun=1.4142 1356 2373 0950 4880 1688 7242 0969 8078 5696 7187 5376 9480 7317 6679 7379 9073 2478 4621 0703 8850 3875 3432 7641 5727 3501 3846 2309 1229 7024 9248 3605 5850 7372 1264 4121 4970 9993 5831 4132 2266 5
19、927 5055 9275 5799 9505 0115 2782 0605 7147 0109 5599 7160 5970 2745 3459 6862 0147 2851 7418 6408 8919 8609 5523 2923 0484 3087 1432 1450 8397 6260 3627 9952 5140 7989 6872 5339 6546 3318 0882 9640 6206 1525 8352 3950 5474 5750 2877 5996 1729 8355 7522 0337 5318 5701 1354 3746 0340 8498 8471 6038 6
20、899 9706 9900 4815 0305 4402 7790 3164 5424 7823 0684 9293 6918 6set num=%nun: =%call :stringlenth %num% numberset /a number=%number%-1set c=1goto main:mainclsset /a number=%number%+1:显示优化,四位一空格。set /a tga=%number%-2if %c%=0 (set a=%num:-1%set /a b=!tga!%4if not %tga%=1 (if %b%=0 set a= !a!)set nun=
21、%nun%!a!) else (set c=0set /a b=!tga!%4)echo.&echo 已经开始计算。echo 在没有看到结尾信息时,请勿关闭本窗口!echo 每计算一位,都会对结果更新!该程序不会对最后一位进行四舍五入。echo 越往后计算,结果显示越慢!请耐心等待本程序计算完成。echo.&echo 计算结果:echo %nun%echo.set /a tga=%number%-2if %tga% geq %bit% goto exitoneif %tga%=0 goto jsksif %tga%=1 (set a1=%num:-1%goto jsks)for /l %i i
22、n (%tga%,-1,1) do (set aaqq=!num:-%i!set a%i=!aaqq:0,1!)goto jsks:jsksset /a tgz=%number%-1set a%number%=0: (下)原为set a%tgz%=!num:0,1!,其结果为1set a%tgz%=1set mainmain=00set z=0goto kfmain:kfmainset /a z+=1if %mainmain%=2m (set a0=1call :jsmaingoto kfmain)if %mainmain%=5m (set a0=2call :jsmaingoto kfmai
23、n)if %mainmain%=4m (set a0=3call :jsmaingoto kfmain)if %mainmain%=2l (set a0=4call :jsmaingoto kfmain)if %mainmain%=00 (set a0=5call :jsmaingoto kfmain)if %mainmain%=7m (set a0=6call :jsmaingoto kfmain)if %mainmain%=5l (set a0=7call :jsmaingoto kfmain)if %mainmain%=9m (set a0=8call :jsmaingoto kfmain)if %mainmain%=7l (set a0=9call :jsmaingoto kfmain)if %mainmain%=1m set tempab=0if %mainmain%=1l set tempab=1if %mainmain%=3m set tempab=2if %mainmain%=3l set tempab=3if %mainmain%=4l set tempab=4if %mainmain%=6m set tempab=5if %mainmain%=6l set te
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1