7017
|
1 ## Copyright (C) 2006, 2007 John W. Eaton |
7016
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
|
18 |
5590
|
19 %% test/octave.test/recursion/recursion-1.m |
|
20 %!function y = f (x) |
|
21 %! if (x == 1) |
|
22 %! y = x; |
|
23 %! return; |
|
24 %! else |
|
25 %! y = x * f (x-1); |
|
26 %! endif |
|
27 %!test |
|
28 %! assert(f (5),120); |
|
29 |
|
30 %% test/octave.test/recursion/recursion-2.m |
|
31 %!function y = f (x) |
|
32 %! if (x == 1) |
|
33 %! y = x; |
|
34 %! return; |
|
35 %! else |
|
36 %! y = f (x-1) * x; |
|
37 %! endif |
|
38 %!test |
|
39 %! assert(f (5),120); |
|
40 |