返回列表 发帖
@echo off
set t=0
for /l %%a in (1 1 100) do (
set/a t+=%%a
)
echo %t%
pauseCOPY

TOP

@echo off&setlocal enabledelayedexpansion
for /l %%i in (1,1,100) do set /a s+=%%i
echo !s!
pauseCOPY
@echo off&setlocal enabledelayedexpansion
set /p n=请输入数字:
for /l %%i in (1,1,!n!) do set /a s+=%%i
echo !b!
pauseCOPY

TOP

::从1加到100
@echo off
set str=0
for /l %%i in (1,1,100) do (
    set /a str+=%%i
)
echo %str%
pause>nulCOPY

TOP

::任意数值的计算
@echo off
set str=0
set /p var=input number
for /l %%i in (1,1,%var%) do (
    set /a str+=%%i
)
echo %str%
pause>nulCOPY

TOP

@echo off
set /a sum=0
for /l %%a in (1 1 100) do (
set/a sum+=%%a
)
echo %sum%
set sum=
pause>nulCOPY

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=請輸入數字:
@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%
pauseCOPY

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

@echo off
set var=0
for /l %%a in (1,1,100) do (set /a var=var+%%a)
echo 1+2+3+4+...+100=%var%
pause>nulCOPY

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

TOP

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

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

@echo off
set /a sum=0
set /p n=请输入一个数字:
for /l %%i in (1,1,%n%) do ( set /a sum+=%%i )
echo %sum%
pauseCOPY

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

@set var=0
@for /l %%i in (1,1,100) do @call set /a var=%%var%%+%%i
@echo %var%
@pauseCOPY
---学无止境---

TOP

返回列表