标题: 批处理中如何进行数值运算呀
[打印本页]
作者: yibo0922
时间: 2006-2-15 17:40
标题: 批处理中如何进行数值运算呀
批处理中怎样进行加减乘除的数值运算呢?
我从文本中取了一个变量,比如说T,取值为19,怎样能给另外一个变量X赋值为18,也就是X=T-1,或者进行其他的运算?
请大家帮帮忙啦
作者: 无奈何
时间: 2006-2-15 19:22
用 set /a 直接计算就可以了。
例:
set t=19
set /a x=t-1
其他计算类似,详情见 set /?
作者: yibo0922
时间: 2006-2-16 08:46
谢谢啦
作者: 3742668
时间: 2006-2-18 07:39
题目:将1-9这9个数字分成三个3位数,要求分出的第一个3位数,正好是第二个三位数的二倍,是第三个3位数的三倍。
@echo off
setlocal
if exist cxs.txt del cxs.txt
if exist startup.txt echo y | del startup.txt
if exist process.txt echo y | del process.txt
set /a var1 = 2
set /a var2 = 1
set /a var3 = 2
set /a i = 0
echo 运算结果: >> cxs.txt
:cxs
if "%var2%"=="10" set /a var3 = %var3% + 2 && set /a var2 = 1 && goto cxs
if "%var3%"=="10" set /a var1 = %var1% + 1 && set /a var3 = 2 && goto cxs
if "%var1%"=="7" goto exit
set /a var2 = %var2% + 1
if "%var1%"=="%var2%" goto cxs
if "%var1%"=="%var3%" goto cxs
if "%var2%"=="%var3%" goto cxs
set /a i = %i% + 1
set /a number = %i% * 100 / 120
cls
echo 当前进度:..........%number%%%
set /a tmp2 = %var1% * 100 + %var2% * 10 + %var3%
set /a tmp1 = %tmp2% / 2
set /a tmp3 = %tmp1% * 3
echo %tmp1%%tmp2%%tmp3% | find "1" || goto cxs
echo %tmp1%%tmp2%%tmp3% | find "2" || goto cxs
echo %tmp1%%tmp2%%tmp3% | find "3" || goto cxs
echo %tmp1%%tmp2%%tmp3% | find "4" || goto cxs
echo %tmp1%%tmp2%%tmp3% | find "5" || goto cxs
echo %tmp1%%tmp2%%tmp3% | find "6" || goto cxs
echo %tmp1%%tmp2%%tmp3% | find "7" || goto cxs
echo %tmp1%%tmp2%%tmp3% | find "8" || goto cxs
echo %tmp1%%tmp2%%tmp3% | find "9" || goto cxs
set /a nums = %tmp1%%tmp2%%tmp3%
echo %tmp3%,%tmp2%,%tmp1% >> cxs.txt
set /a tmp1 = 0
set /a tmp2 = 0
set /a tmp3 = 0
goto cxs
:exit
cls
echo 共计算了%i%次. >> cxs.txt
endlocal
echo ************************* >>cxs.txt
echo 孤狗 QQ:3742668 >>cxs.txt
echo ************************* >>cxs.txt
exit
电脑报第36期编程魔方的题目。
用CMD写了一个,带进度条显示,本来还有一些系统检查的功能的,这里去掉了。其实不用那么多代码的,只不过为了减少运算的次数提高效率以及显示进度等等才多了不少行。。。
[
Last edited by 3742668 on 2006-2-18 at 07:40 ]
作者: voiL
时间: 2006-2-18 20:23
从4楼中又学到了点东西.....
作者: 3742668
时间: 2006-2-18 22:21
见笑了,呵呵,其实这个东东还可以简化,只是当时水平有限,不堪入目之处希望老鸟们不要见笑。。。
作者: htysm
时间: 2006-6-26 20:57
对于我等菜鸟来说,这里是高手如云滴.