China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-02 04:59
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Batch script to calculate the value of 1+2+3+4……+100 ```batch @View code @echo("off @setlocal @set sum=0 @for /l %%i in (1,1,100) do ( @set /a sum=%%i+sum ) @echo The sum is %sum% @endlocal ``` 批处理计算1+2+3+4……100的值 ```batch @View code @echo("off @setlocal @set sum=0 @for /l %%1 in (1,成成,public) out of order ``` 批处理计算1+2+3+4……100的值 ```batch @View code @Manual code和Well-sent code【是成成、public.com的输出成乱了】 @echo("Some random characters" @setlocal @set sum=0 @for (1,1,100) do ( 成成 ) @echo The out-of-order sum is %sum% @endlocal ``` Batch script to calculate the value of 1+2+3+4……+100 ```batch @View code @echo("off @setlocal @set sum=0 @for /l %%i in (1,1,100) do ( @set /a sum=%%i+sum ) @echo The sum is %sum% @endlocal ``` 批处理计算1+2+3+4……100的值 ```batch @View code @echo("off @setlocal @set sum=0 @for /l %%1 in (1,成成,public) out of order ``` 批处理计算1+2+3+4……100的值 ```batch @View code @Manual code和Well-sent code【是成成、public.com的输出成乱了】 @echo("Some random characters" @setlocal @set sum=0 @for (1,1,100) do ( 成成 ) @echo The out-of-order sum is %sum% @endlocal ``` Batch script to calculate the value of 1+2+3+4……+100 ```batch @echo off @setlocal enabledelayedexpansion @set sum=0 @for /l %%i in (1,1,100) do ( set /a sum=!sum!+%%i ) @echo The sum is %sum% @endlocal ``` 批处理计算1+2+3+4……100的值 ```batch 【成成都成了public的输出 said is成成,请说成成】 ``` Batch script to calculate the value of 1+2+3+4……+100 ```batch @echo off @setlocal enabledelayedexpansion @set sum=0 @for /l %%i in (1,1,100) do ( set /a sum=!sum!+%%i ) @echo The sum is %sum% @endlocal ``` 批处理计算1+2+3+4……100的值 ```batch 【成成都成了public的输出 said is成成,请说成成】 ``` Batch script to calculate the value of 1+2+3+4……+100 ```batch @echo off @setlocal enabledelayedexpansion @set sum=0 @for /l %%i in (1,1,100) do ( set /a sum=!sum!+%%i ) @echo The sum is %sum% @endlocal ``` Okay, let's go through this step by step. First, the user is trying to get batch scripts to calculate the sum of 1 to 100. Let's handle each part properly. The first set of code that's mostly correct is: ```batch @echo off @setlocal enabledelayedexpansion @set sum=0 @for /l %%i in (1,1,100) do ( set /a sum=!sum!+%%i ) @echo The sum is %sum% @endlocal ``` Then there are some parts with garbled text which we can just note the correct structure. The key is to present the correct batch script for calculating the sum from 1 to 100. So compiling the correct translations and code blocks: Batch script to calculate the value of 1+2+3+4……+100 ```batch @echo off @setlocal enabledelayedexpansion @set sum=0 @for /l %%i in (1,1,100) do ( set /a sum=!sum!+%%i ) @echo The sum is %sum% @endlocal ``` For the parts with garbled text, since they don't contribute to the correct functionality, we can just focus on the valid code. The final translated and correct code block for calculating the sum from 1 to 100 in batch is as above. View 4,690 Replies 21
Floor 16 Posted 2008-03-02 13:26 ·  中国 北京 华为云
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
Enable command extensions
Bring the parameter %%a in call :aaa %%a to the :aaa label and use %1 instead to use it
Format: call + label + parameter
I don't know if I expressed it clearly
See the help call /? for details
Floor 17 Posted 2008-03-02 21:04 ·  中国 浙江 绍兴 电信
初级用户
Credits 114
Posts 5
Joined 2004-01-30 00:00
22-year member
UID 16358
Gender Male
Status Offline
@echo off
setlocal enabledelayedexpansion
set s=0
for /l %%a in (1,1,500 ) do (
set /a s=%%a+!s!
set d=!d!+%%a
echo !d!=!s!
ping -n 1 127.1 >nul
cls
)
echo %d%=%s%
pause >nul
Floor 18 Posted 2008-03-02 21:05 ·  中国 广东 阳江 电信
初级用户
Credits 20
Posts 9
Joined 2007-11-05 23:23
18-year member
UID 101826
Gender Male
Status Offline
Earning one point by posting.
Floor 19 Posted 2008-03-03 11:41 ·  中国 重庆 电信
初级用户
Credits 34
Posts 14
Joined 2007-12-13 18:21
18-year member
UID 105563
Gender Male
Status Offline
@echo off
set aa=0
for /l %%a in (1,1,100) do (
call :aaa %%a
)
pause
goto :eof
:aaa
set /a aa=%1+%aa%
echo %aa%

"set /a means to perform an operation (operator parameters), %1 is %%a in call :aaa %%a, which is the parameter brought in by call :aaa, for example, after call :aaa %%a %%b %%c..., to reference the parameter, use %1 %2 %3... to represent"
- - - - - - The above explanation comes from moniuming
Floor 20 Posted 2010-10-22 20:27 ·  中国 福建 厦门 电信
新手上路
Credits 1
Posts 1
Joined 2010-06-11 20:08
16-year member
UID 168638
Gender Male
Status Offline
```batch
@echo off
set n=1
set /p n=input a number!
for /l %%i in (1,1,%n%) do (
set /a sum+=%%i
)
echo %sum%
pause
```
Floor 21 Posted 2010-12-27 21:08 ·  中国 广东 东莞 中移铁通
初级用户
★★
Credits 115
Posts 92
Joined 2010-12-24 16:57
15-year member
UID 179794
Gender Male
Status Offline
Learning
Floor 22 Posted 2011-01-17 10:37 ·  中国 吉林 长春 电信
初级用户
枫中残雪
Credits 65
Posts 43
Joined 2010-04-29 23:20
16-year member
UID 165810
Gender Male
From 吉林省长春市
Status Offline
Bored, write one


@echo off
set b=0
:1
set /a b+=1
set /a a+=%b%
if "%b%" equ "100" (echo %a% &pause&exit) else goto 1
Forum Jump: