Skip to content

Latest commit

 

History

History
80 lines (63 loc) · 965 Bytes

c300_程式閱讀題.md

File metadata and controls

80 lines (63 loc) · 965 Bytes




遞迴函數(Recursive function)

設有一副程式如下         
Function f(x,y:integer):integer,
begin
if y=0 then f=1;
else f:=f(x,y-1)*x;
end; 
若a,b均為正整數,則呼叫f(a,b)時的結果為:
(A) a*b   (B) a+b   (C) a**b(代表a的b乘方)  (D) a/b

c語言之函數fun1之定義如下
int fun1(int n)
{
		if(n==0)
			Return(2);
		else if(n==1)
		return(1);
	else
		return(2*fun1(n-1)+3*fun1(n-2));
}
試問fun(5)=?(A) 87  (B) 143  (C) 181  (D) 217 

程式閱讀題_

有一Recursive的C語言程式如下,試間P(3)=?
	Int f(int x)
	{
	if(x<=1)
		   return 1;
	else
		return (x2+f(x-1));
} (A) 10 (B) 12  (C) 14 (D) I6 (E) 30

c語言之函數fun 1之定義如下
	int fun1(int n)
	{
		if(n==0)
			Return(2);
		else if(n==1)
		return(1);
	else
		return(2*fun1(n-1)+3*fun1(n-2));
}
試問fun(5)=?(A) 87  (B) 143  (C) 181  (D) 217