能准确判断纯数字
- @echo off
- :loop
- set /p n=请输入:
- set m=%n%
- for %%a in (0 1 2 3 4 5 6 7 8 9) do (
- call set n=%%n:%%a=%%
- if not defined n goto start)
- goto loop
- :start
- set "sum="
- for /l %%i in (1 1 %m%) do ( set /a sum=sum+%%i)
- echo 1+2+....+n=%sum%
- pause>nul
- goto loop
复制代码
第二种方法:不能区分124asd 和124
- @echo off
- :lop
- cls
- set /p n=输入你想计算的数字n=:
- 2>nuo set /a 1/n || goto lop
- set "sum="
- for /l %%i in (1 1 %n%) do ( set /a sum=sum+%%i)
- echo 1+2+....+n=%sum%
- pause>nul
- goto lop
复制代码
[ 本帖最后由 inittab 于 2009-6-2 19:49 编辑 ] |