联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!
@echo off setlocal enabledelayedexpansion ::::::::::::::::::::::::::::Find The Biggest Public Divisor:::::::::::::::::::::::::::: :::::::::::::::::::::::::::: {s11ss 2007-9-21} :::::::::::::::::::::::::::: :r echo Please input two integers,like 9,21: set /p n= echo. echo Calculating... set /a i=1 for %%a in (!n!) do ( set n!i!=%%a set /a i+=1 ) if !n1! equ !n2! ( call :e !n1! goto :eof ) if !n1! lss !n2! ( set t=!n1! set n1=!n2! set n2=!t! ) set /a big=!n1! set /a small=!n2! :c set /a remain=!big!%%!small! if !remain! equ 1 ( echo. echo They don't have the public divisor. goto :e ) if !remain! equ 0 ( echo. echo The biggest public divisor is !small!. goto :e ) else ( set big=!small! set small=!remain! goto :c ) :e echo. echo Press Any Key To Exit... pause>nul
@echo off 2>nul 3>nul& setlocal enabledelayedexpansion echo 请输入几个整数,类似:21 7 14 set /p n= set num2=%n:* =% for %%i in (%n%) do call :test %%i !num2! echo 它们的公约数为:%num2% pause>nul :test %num1% %num2% set /a temp=%1 %% %2 if %temp% NEQ 0 ( set/a num1=%2,num2=%temp% call :test !num1! !num2!) else set num2=%2