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

来源:互联网 发布:北京网络营销策划公司 编辑:程序博客网 时间:2024/05/21 17:02
 <%@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>

原创粉丝点击