返回列表 发帖
现学现卖中~
@echo off
set %%i=1
for /l %%i in (1 1 100) do set /a sum+=%%i
echo %sum%
pause

sum+=%%i这个参数弄了老半天
想通了~~以前有学过C++的一点基础。现在想起来了,暴汗!

至于提高题:
@echo off
set %%i=1
set /p n= 请输入N的值
for /l %%i in (1 1 %n%) do set /a sum+=%%i
echo %sum%
pause
嘿嘿,难倒不难,新手来的,批处理懂得太少了~~
格式方面不知道有什么错误没

[ 本帖最后由 xwfswh 于 2008-10-30 21:35 编辑 ]
尘莫央

TOP

@echo off &title 累加计算&color 1a&mode con cols=35 lines=10
set /p n=请输入从1累加到几的那个数:
set /a t=0
for /l %%i in (1,1,%n%) do (set /a t=t+%%i)
echo 累加结果是:%t%
pause >nul

TOP

@echo off
set /p n=请输入N:
set num=0
FOR /l %%i in (1 1 %n%) do (
set /a num+=%%i
)
echo 1+2+3+...+%n%=%num%
pause>nul COPY

TOP

@echo off
for /l %%i in (100,-1,1) do set /a sum+=%%i
echo %sum%
pause>nul

TOP

前几天有事,现在又可以坐下来学习了
@echo off
for /l %%i in (1 1 100) do (set /a sum+=%%i)
echo 1+2+3+...+100=%sum%
pause

TOP

@echo off&setlocal EnableDelayedExpansion
set /p num=请输入数字:
for /l %%a (1 1 %num%) do (
set /a n=n+%%a
)
echo 运算结果:!n!
pause>nulCOPY

[ 本帖最后由 zcy85611 于 2009-1-19 10:53 编辑 ]

TOP

@echo off
set /p nax=1+2+3+4+. . . . . . . . . . . . . +
set /a answer=(1+%nax%)*%nax%/2
echo %answer%
pause > nul


看见第一楼用的for,我感觉既然公差一定用求和公式就好了
setlocal enabledelayedexpansion

TOP

@echo off
set x=1
for /l %%a in (2,1,100) do (
set /a x=x+%%a
)
echo %x%
pauseCOPY

TOP

@echo off
set /p x=1+2+3+4+5+6+7+8+9+~~~~~:
set y=1
for /l %%a in (2,1,%x%) do set /a y=y+%%a
echo %y%
pauseCOPY

TOP

我来试

@echo off
:main
set aa=
setlocal enabledelayedexpansion
set /p n=请输入数字n:
for /l %%i in (1,1,%n%) do (
set /a aa=!aa!+%%i)
echo !aa!
pause>nul
goto :mainCOPY
算法真简单

TOP

@echo off
:main
set aa=
setlocal enabledelayedexpansion
set /p n=请输入数字n:
for /l %%i in (1,1,%n%) do (
set /a aa=!aa!+%%i)
echo !aa!
pause>nul
goto :mainCOPY

TOP

@echo off
set/p n=  input a number :
set/a s=n-1,s*=n/2,s+=n
echo %s%
pauseCOPY

[ 本帖最后由 zhouyongjun 于 2009-2-16 11:54 编辑 ]

TOP

回复 1楼 的帖子

@echo off
setlocal enabledelayedexpansion
for /l %%i in (1 1 100) do (
set /a tt+=%%i,sum=tt-1)
echo !sum!

TOP

@echo off
set /p n= 请输入最后一个数:
set /a sum=(1+%n%)*%n%/2
echo 总和:%sum%
pauseCOPY
(*^_^*)

TOP

计算1到100

@echo off
setlocal enabledelayedexpansion
set a=0
for /l %%i in (1,1,100) do set /a a=a+%%i
echo 1到100的数字之和为%a%
pause>nul

计算1到n

@echo off
echo 计算1+2+3+...+n=?
setlocal enabledelayedexpansion
set /p a=请输入n为几:
set b=0
for /l %%i in (1,1,%a%) do set /a b=b+%%i
echo 1到%a%的数字之和为%b%
pause>nul

TOP

返回列表