您的位置:首页 > 编程语言 > ASP

求1,1,2,3,5,8,13,21,34...的第N位結果For ASP

2008-12-09 13:06 176 查看
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>求1,1,2,3,5,8,13,21,34,......的第N位結果</title>
</head>
<%
'==========================================
' 求1,1,2,3,5,8,13,21,34,......的第N位結果
' 遞迴方法
'==========================================
on error resume next
Server.ScriptTimeOut=999999 ''處理資料可能需要長時間
a=trim(request("t1"))
if a="" then
response.Write("Please input number in textbox")
else
Response.Write("第"+a+"位的結果是:")
Response.Write(foo(cint(a)))
end if
'递归函数求第N位结果
function foo(a)
if a<=0 then
foo=0
elseif a=1 or a=2 then
foo=1
else
foo=foo(a-1)+foo(a-2)
end if
end function
%>
<form name="form1" method="post" action="">
<input name="t1" type="text" id="t1" size="20">
<input type="submit" name="Submit" FONT-FAMILY: 'PMingLiU','serif'; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">提交">
</form>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐