小无聊一下,不过真的很强大……

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
@ECHO OFF

SETLOCAL

SET X=10

CALL :Fib %X% Y
ECHO Fib^(%X%^)=%Y%
GOTO :EOF

:Fib [In]X [Out]Result
SETLOCAL
SET A=%1
SET D=1
SET E=0

IF %A% LEQ 1 (
    GOTO FibRet
)

SET /A B=%A%-1
SET /A C=%A%-2
CALL :Fib %B% D
CALL :Fib %C% E

:FibRet
ENDLOCAL & SET /A %2=%D%+%E% & GOTO :EOF

输出是“Fib(10)=89”

您还可能感兴趣的日志:

  1. 强大的批处理 (3) 判断目录在%Path%中
  2. 强大的批处理 (4) 使用数组
  3. 强大的批处理 (1) 字符串截取

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

   
© 2004 - 2011 Leona+Suffusion theme by Sayontan Sinha