Pascal:用递归函数求斐波那契数列的第n项·用递归函数输出斐波那契数列(0,1,1,2,3,5,8,13……)的第n项·哥哥姐姐帮帮忙啊····

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/10 06:35:52

Pascal:用递归函数求斐波那契数列的第n项·用递归函数输出斐波那契数列(0,1,1,2,3,5,8,13……)的第n项·哥哥姐姐帮帮忙啊····
Pascal:用递归函数求斐波那契数列的第n项·
用递归函数输出斐波那契数列(0,1,1,2,3,5,8,13……)的第n项·哥哥姐姐帮帮忙啊····

Pascal:用递归函数求斐波那契数列的第n项·用递归函数输出斐波那契数列(0,1,1,2,3,5,8,13……)的第n项·哥哥姐姐帮帮忙啊····
function fibonacci(n:integer):integer begin if (n=0) then Result:=0; if (n=1) then Result:=1; if (n>1) then Result:=fibonacci(n-1)+fibonacci(n-2); end; 追问: Result 是什么意思啊它说 not found‘’Result‘’麻烦写的完整些(连主程序)好吗. 回答: Result 是delphi函数的 返回值 ,pascal可以使用函数名 function fibonacci(n:integer):integer begin if (n=0) then fibonacci:=0; if (n=1) then fibonacci:=1; if (n>1) then fibonacci:=fibonacci(n-1)+fibonacci(n-2); end; begin writeln('the 10th number is',fibonacci(10)); end; 追问: 按照题意中间应该是 if n=1 then fibonacci:=0; if n=2 then fibonacci:=1; if n>2 then ……不过还是要谢谢你