The funmation valne f ( x,5 )

2009-04-03 7:37 pm
Given a Recursive fumction below;
fumction f ( x, n : integer ) : integer ;
Begin
if n= 1 then f := x
else f :=x*f ( x,n-1 )
end ;
Find
(a) The funmation valne f ( x,5 )
(b) The number of recursive calls in evaluating f (x,5)

回答 (2)

2009-04-03 8:05 pm
✔ 最佳答案
這個是 pascal / delphi 的吧...怎麼會貼到C/C++這邊?!

2009-04-03 12:05:40 補充:
(a)
f(x,5) = 5 * f(x, 4) = 5 * 4 * f(x, 3) = 5*4*3*f(x, 2) = 5*4*3*2*f(x,1)
=5*4*3*2*1
=120
(b)
5次
2009-04-04 8:25 am
a) should be x^5, the logic follows:

f :=x*f ( x,n-1 ) when n=5
f :=x*f ( x,n-1 ) when n=4
f :=x*f ( x,n-1 ) when n=3
f :=x*f ( x,n-1 ) when n=2
f :=x when n=1
when everything recurses back, f=x*x*x*x*x = x^5


收錄日期: 2021-04-30 13:08:07
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20090403000015KK02938

檢視 Wayback Machine 備份