程序1 | @echo off&setlocal enabledelayedexpansion | | set n=100 | | for /l %%a in (1,1,4) do ( | | for /l %%b in (1,1,4) do ( | | for /l %%c in (1,1,4) do ( | | for /l %%d in (1,1,4) do ( | | if not %%a==%%b if not %%a==%%c if not %%a==%%d if not %%b==%%c if not %%b==%%d if not %%c==%%d if not defined _n set /a _!n!=%%a%%b%%c%%d&set /a t1+=1&set /a n+=1 | | ) | | ) | | ) | | ) | | for /f "tokens=2 delims==" %%a in ('set _') do echo;%%a | | echo;!t1! | | pauseCOPY |
程序4 | @echo off&setlocal enabledelayedexpansion | | title 判断一年第几天 | | :begin | | set /p d=输入某年某月末日(2015-08-05): | | set n=%d:~,4% | | set y=%d:~5,2% | | set r=%d:~8,2% | | if %y% gtr 12 echo;错误。&ping /n 3 127.1>nul&goto begin | | if %r% gtr 31 echo;错误。&ping /n 3 127.1>nul&goto begin | | if %y:~,1%==0 set y=%y:~1% | | if %r:~,1%==0 set r=%r:~1% | | set /a y1=%y%-2 | | echo;%n%-%y%-%r% | | set /a n1=%n%%%400 | | set /a n2=%n%%%100 | | set /a n3=%n%%%4 | | if %n1%==0 ( | | set /a n=1 | | ) else ( | | if not %n2%==0 ( | | if %n3%==0 (set /a n=1) else (set /a n=0) | | ) | | ) | | if %y%==1 echo;这是一年第%r%天。 | | if not %y%==1 ( | | if %y% gtr 1 set /a n+=1 | | if %y% gtr 3 set /a n+=1 | | if %y% gtr 5 set /a n+=1 | | if %y% gtr 7 set /a n+=1 | | if %y% gtr 8 set /a n+=1 | | if %y% gtr 10 set /a n+=1 | | if %y% gtr 12 echo;超过12个月了。&ping /n 3 127.1>nul&goto begin | | set /a t=%y1%*30+!n!+!r!+28 | | echo;这是一年第!t!天。 | | ) | | pauseCOPY |
程序8 | @echo off&setlocal enabledelayedexpansion | | title 九九乘法表 | | for /l %%a in (1,1,9) do ( | | for /l %%b in (1,1,%%a) do ( | | set /a n=%%a*%%b | | set /p=%%a*%%b=!n! <nul | | ) | | echo. | | ) | | pauseCOPY |
程序11 | @echo off&setlocal enabledelayedexpansion | | set /p num=几月份 | | set /a n1=1 | | set /a n2=0 | | :a | | set /a n=%n1%+%n2% | | echo;%n% | | set /a n1=%n2% | | set /a n2=%n% | | set /a t+=1 | | if %t%==%num% goto b | | goto a | | :b | | pauseCOPY |
程序12 | @echo off&setlocal enabledelayedexpansion | | for /l %%a in (100,1,200) do ( | | set k= | | set /a n=%%a-1 | | for /l %%b in (2,1,!n!) do ( | | set /a num=%%a%%%%b | | if !num!==0 set /a k+=1 | | ) | | if not defined k echo;%%a | | ) | | pauseCOPY |
程序13 | @echo off&setlocal EnableDelayedExpansion | | for /l %%a in (1,1,9) do ( | | for /l %%b in (0,1,9) do ( | | for /l %%c in (0,1,9) do ( | | set /a n1=%%a*%%a*%%a | | set /a n2=%%b*%%b*%%b | | set /a n3=%%c*%%c*%%c | | set /a n=!n1!+!n2!+!n3! | | if !n!==%%a%%b%%c echo;%%a%%b%%c | | ) | | ) | | ) | | pauseCOPY |
程序14 | @echo off&setlocal enabledelayedexpansion | | set num=1 | | set /p n=请输入要分解的数 | | :a | | set /a k2=%n%%%2 | | set /a k3=%n%%%3 | | if %num%==1 if not %k2%==0 if not %k3%==0 (echo;本身就是质数。) | | set /a num+=1 | | if %k2%==0 set /a n=%n%/2&set z=%z%*2 | | if not %k2%==0 if %k3%==0 set /a n=%n%/3&set z=%z%*3 | | if not %k2%==0 if not %k3%==0 (set z=%z%*%n%&goto b) | | goto a | | :b | | echo;%z:~1% | | pauseCOPY |
程序16 | @echo off&setlocal enabledelayedexpansion | | title 最大公约数和最小公倍数 | | set /p m=请输入第一个数字: | | set /p n=请输入第二个数字: | | set /a a=%m%,b=%n% | | :a | | set /a y=%m%%%%n% | | if %y%==0 echo;%n%是最大公约数。&goto b | | set /a m=%n%,n=%y% | | goto a | | :b | | set /a num=%a%*%b%/%n% | | echo;%num%是最小公倍数。 | | pauseCOPY |
程序19 | @echo off&setlocal enabledelayedexpansion | | title 1000以内的所有完数 | | set m=0 | | for /l %%a in (1,1,1000) do ( | | set m= | | set /a k=%%a-1 | | for /l %%b in (1,1,!k!) do ( | | set /a n=%%a%%%%b | | if !n!==0 set /a m=!m!+%%b | | ) | | if %%a==!m! echo;%%a | | ) | | pauseCOPY |
程序20 | @echo off&setlocal enabledelayedexpansion | | set n=1000000000 | | set num=1000000000 | | :a | | set /a m=%n%/2 | | set n=%m% | | set /a t+=1 | | set /a num=%num%+%m% | | if %t%==10 goto b | | goto a | | :b | | for /l %%a in (0,1,20) do ( | | if not "!num:~%%a,1!"=="" set /a t1+=1 | | if not "!m:~%%a,1!"=="" set /a t2+=1 | | ) | | set /a t4=7-!t2! | | if !t4!==1 set t5=0 | | if !t4!==2 set t5=00 | | if !t4!==3 set t5=000 | | if !t1! gtr 7 ( | | set num1=!num:~-7! | | call,set num=%%num:!num1!=%% | | set /p=共经过!num!.!num1!米,<nul | | ) | | if !t2! leq 7 ( | | set /p=第10次反弹0.!t5!!m!。<nul | | ) | | pauseCOPY |
程序21 | @echo off&setlocal enabledelayedexpansion | | set n=1 | | for /l %%a in (1,1,9) do ( | | set /a n=!n!*2+1 | | ) | | echo;!n! | | pauseCOPY |
程序23 | @echo off&setlocal enabledelayedexpansion | | set n=* | | set t=1 | | for /l %%a in (1,1,7) do ( | | set /a num=%%a%%2 | | if %%a leq 4 ( | | echo;!n! | | if %%a lss 4 if !num!==0 (set n=!n!***&set /a t+=3) else (set n=!n!**&set /a t+=2) | | ) | | if %%a gtr 4 ( | | if !num!==0 (set /a t-=3) else (set /a t-=2) | | call,echo;%%n:~,!t!%% | | ) | | ) | | pauseCOPY |
程序25 | @echo off&setlocal enabledelayedexpansion | | set num=1 | | set shuzi=0 | | for /l %%a in (1,1,20) do ( | | set num= | | for /l %%b in (1,1,%%a) do ( | | set num=!num!*%%b | | ) | | set /a num=!num:~1! | | set /a shuzi=!shuzi!+!num! | | ) | | echo;!shuzi! | | pauseCOPY |
程序30 | @echo off&setlocal enabledelayedexpansion | | titile 回文数 | | for /l %%a in (1,1,9) do ( | | for /l %%b in (0,1,9) do ( | | for /l %%c in (0,1,9) do ( | | for /l %%d in (0,1,9) do ( | | for /l %%e in (0,1,9) do ( | | if %%a==%%e if %%b==%%d echo;%%a%%b%%c%%d%%e | | ) | | ) | | ) | | ) | | ) | | pauseCOPY |
程序37 | @echo off&setlocal enabledelayedexpansion | | title 排序 | | set /p n1=输入第1个数字: | | set /p n2=输入第2个数字: | | set /p n3=输入第3个数字: | | set /p n4=输入第4个数字: | | set /p n5=输入第5个数字: | | set /p n6=输入第6个数字: | | set /p n7=输入第7个数字: | | set /p n8=输入第8个数字: | | set /p n9=输入第9个数字: | | set /p n10=输入第10个数字: | | for /l %%a in (0,1,10000000) do ( | | for /l %%b in (1,1,10) do ( | | if %%a==!n%%b! echo;%%a | | ) | | ) | | pauseCOPY |
程序69 | @echo off&setlocal enabledelayedexpansion | | set /p r=总人数: | | for /l %%a in (1,1,%r%) do ( | | set /a n=%%a%%3 | | if not !n!==0 set num=!num! %%a | | ) | | for %%a in (!num!) do set shuzi=%%a | | echo;!shuzi! | | pauseCOPY |
程序80 | @echo off&setlocal enabledelayedexpansion | | title 分桃子 | | set /a n1=1,n2=1 | | for /l %%a in (1,1,5) do ( | | set /a n1=!n1!*4 | | set /a n2=!n2!*5 | | ) | | echo;!n1! | | echo;-----*n | | echo;!n2! | | set /a n3=!n2!-4 | | | | echo;原来的桃子最少有:!n3!个。 | | pauseCOPY |
程序83 | @echo off&setlocal enabledelayedexpansion | | title 求0—7所能组成的奇数个数 | | for /l %%a in (0,1,7) do ( | | for /l %%b in (0,1,7) do ( | | for /l %%c in (0,1,7) do ( | | for /l %%d in (0,1,7) do ( | | for /l %%e in (0,1,7) do ( | | for /l %%f in (0,1,7) do ( | | for /l %%g in (0,1,7) do ( | | set /a n=%%g%%2 | | if not !n!==0 if not defined _%%a if not defined _%%b if not defined _%%c if not defined _%%d if not defined _%%e if not defined _%%f if not defined _%%g ( | | set _%%a+=1&set _%%b+=1&set _%%c+=1&set _%%d+=1&set _%%e+=1&set _%%f+=1&set _%%g+=1 | | echo;%%a%%b%%c%%d%%e%%f%%g&set /a t+=1 | | ) | | ) | | ) | | ) | | ) | | ) | | ) | | ) | | echo;!t! | | pauseCOPY |
程序84 | @echo off&setlocal enabledelayedexpansion | | title 一个偶数总能表示为两个素数之和(1000以内) | | set /p shuzi=输入一个偶数: | | for /l %%a in (2,1,1000) do ( | | set t=0 | | set /a n=%%a-1 | | for /l %%b in (2,1,!n!) do ( | | set /a n1=%%a%%%%b | | if !n1!==0 set /a t+=1 | | ) | | if !t!==0 set num=!num! %%a | | ) | | for %%a in (!num:~1!) do ( | | for %%b in (!num:~1!) do ( | | set /a shuzi1=%%a+%%b | | if !shuzi1!==!shuzi! echo;%%a %%b | | | | ) | | ) | | pauseCOPY |
程序24 | @echo off&setlocal enabledelayedexpansion | | title 前20项的和 | | set /a n1=2,n2=3,n3=1,n4=2 | | set "num=%n1% %n2%" | | set "shuzi=%n3% %n4%" | | set qiuhe=2/1+3/2 | | for /l %%a in (1,1,18) do ( | | set /a n=!n1!+!n2! | | set /a n5=!n3!+!n4! | | set "num=!num! !n!" | | set "shuzi=!shuzi! !n5!" | | set /a qiuhe=!qiuhe!+!n!/!n5! | | set n3=!n4!&set n4=!n5! | | set n1=!n2!&set n2=!n! | | ) | | echo;分子:!num! | | echo;分母:!shuzi! | | echo;和为!qiuhe! | | pauseCOPY |
程序67 | @echo off&setlocal enabledelayedexpansion | | set /p num=输入一个数字(不重复): | | for /l %%a in (0,1,10) do ( | | set n=100 | | set shuzi=!num:~%%a,1! | | for /l %%b in (0,1,9) do ( | | if %%b==!shuzi! ( | | set /a n=!n!+%%b | | if not defined _n ( | | set /a _!n!+=1 | | ) | | ) | | ) | | ) | | for /f "tokens=1 delims==" %%a in ('set _') do ( | | set k=%%a | | set k=!k:~-1! | | set /a t+=1 | | if !t!==1 (set s=!k!) | | ) | | set num3=%num:~0,1% | | set num4=%num:~-1% | | set num=%num:~1% | | call,set num=%%num:!num4!=%% | | call,set num=%%num:!k!=!num3!%% | | call,set num=%%num:!s!=!num4!%% | | echo;!k!!num!!s! | | pauseCOPY |
|