You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
504 B
69 lines
504 B
2 years ago
|
|
||
|
Exercise 1.11: A function
|
||
|
f
|
||
|
is defined by
|
||
|
the rule that
|
||
|
|
||
|
f
|
||
|
(
|
||
|
n
|
||
|
)
|
||
|
=
|
||
|
n
|
||
|
|
||
|
if
|
||
|
|
||
|
n
|
||
|
<
|
||
|
3
|
||
|
|
||
|
and
|
||
|
|
||
|
f
|
||
|
(
|
||
|
n
|
||
|
)
|
||
|
|
||
|
=
|
||
|
|
||
|
f
|
||
|
(
|
||
|
n
|
||
|
−
|
||
|
1
|
||
|
)
|
||
|
|
||
|
+
|
||
|
|
||
|
2
|
||
|
f
|
||
|
(
|
||
|
n
|
||
|
−
|
||
|
2
|
||
|
)
|
||
|
|
||
|
+
|
||
|
|
||
|
3
|
||
|
f
|
||
|
(
|
||
|
n
|
||
|
−
|
||
|
3
|
||
|
)
|
||
|
|
||
|
if
|
||
|
|
||
|
n
|
||
|
≥
|
||
|
3
|
||
|
|
||
|
.
|
||
|
Write a procedure that computes
|
||
|
f
|
||
|
by means of a recursive process. Write a procedure that
|
||
|
computes
|
||
|
f
|
||
|
by means of an iterative process.
|