[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
  1. @echo off
  2. set t=0
  3. for /l %%a in (1 1 100) do (
  4. set/a t+=%%a
  5. )
  6. echo %t%
  7. pause
复制代码

TOP

  1. @echo off&setlocal enabledelayedexpansion
  2. for /l %%i in (1,1,100) do set /a s+=%%i
  3. echo !s!
  4. pause
复制代码
  1. @echo off&setlocal enabledelayedexpansion
  2. set /p n=请输入数字:
  3. for /l %%i in (1,1,!n!) do set /a s+=%%i
  4. echo !b!
  5. pause
复制代码

TOP

  1. ::从1加到100的
  2. @echo off
  3. set str=0
  4. for /l %%i in (1,1,100) do (
  5.     set /a str+=%%i
  6. )
  7. echo %str%
  8. pause>nul
复制代码

TOP

  1. ::任意数值的计算
  2. @echo off
  3. set str=0
  4. set /p var=input number
  5. for /l %%i in (1,1,%var%) do (
  6.     set /a str+=%%i
  7. )
  8. echo %str%
  9. pause>nul
复制代码

TOP

  1. @echo off
  2. set /a sum=0
  3. for /l %%a in (1 1 100) do (
  4. set/a sum+=%%a
  5. )
  6. echo %sum%
  7. set sum=
  8. pause>nul
复制代码

TOP

@echo off
:abc
cls
set /a i = 1
set /p n=請輸入數字:
if {%n%}=={} goto abc
:acb
set /a i+=1,j+=i
if %i% neq %n% goto acb
echo %j%
pause

TOP

@echo off
:abc
cls
set /a i = 1
set /p n=請輸入數字:
  1. @echo off
  2. :abc
  3. cls
  4. set /a i = 1
  5. set /p n=請輸入數字:
  6. if {%n%}=={} goto abc
  7. :acb
  8. set /a i+=1,j+=i
  9. if %i% neq %n% goto acb
  10. echo %j%
  11. pause
复制代码

if {%n%}=={} goto abc
:acb
set /a i+=1,j+=i
if %i% neq %n% goto acb
echo %j%
pause

TOP

{code}
@echo off
set a=0
set b=0
:a
echo +%a%=%b%
set /a a+=1
set /a b=%b%+%a%
if %a% gtr 100 (pause) else (goto a
exit
{/code}

TOP

  1. @echo off
  2. set var=0
  3. for /l %%a in (1,1,100) do (set /a var=var+%%a)
  4. echo 1+2+3+4+...+100=%var%
  5. pause>nul
复制代码

[ 本帖最后由 zsllq 于 2010-10-27 15:36 编辑 ]

TOP

  1. @echo on&setlocal enabledelayedexpansion
  2. set sum=0
  3. for /l %%i in (1,1,100) do (set /a sum+=%%i)
  4. echo 1+2+...+100=!sum!
  5. pause
复制代码
看得多说得多,远比不上写得多。

TOP

回复 12楼 的帖子

sum+=%%i   为什么sum不用初始化结果也对呢???????

TOP

:c
Set /a s+=1
set /a b+=%s%
if %b% equ 100 echo %b% || goto c
pause

TOP

  1. @echo off
  2. set /a sum=0
  3. set /p n=请输入一个数字:
  4. for /l %%i in (1,1,%n%) do ( set /a sum+=%%i )
  5. echo %sum%
  6. pause
复制代码

TOP

set /p a=请输入:
echo %a%|findstr "^[1-9][0-9]*$" >nul
for /l %%i in (1,1,%a%) do (set /a b+=%%i)
echo %b%
pause
虽然是借鉴了两位高手的答案
还是学会了,很开心..

TOP

  1. @set var=0
  2. @for /l %%i in (1,1,100) do @call set /a var=%%var%%+%%i
  3. @echo %var%
  4. @pause
复制代码
---学无止境---

TOP

返回列表