求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>
<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>
![](http://imgcache.qq.com/ac/b.gif)
相关文章推荐
- 求1,1,2,3,5,8,13,21,34...的第N位結果For ASP
- 求斐波那契数列第n项,n<30,斐波那契数列前10项为 1,1,2,3,5,8,13,21,34,55
- 使用递归求出0,1,1,2,3,5,8,13,21,34.........数列的第20项为多少
- 算法:【一列数的规则如下: 1、1、2、3、5、8、13、21、34 ,求第30位数是多少, 用递归算法实现。(C#语言)】
- 用递归算法实现1、1、2、3、5、8、13、21、34......
- 0 1 1 2 3 5 8 13 21 34 求第N个, 用js实现
- JS:定义函数求斐波那契数列(特点:第1和2个数都是1,随后的数字是它前两个数字的和,如1,1,2,3,5,8,13,21,34,......)
- 5.斐波那契数组:循环和递归;输入n时判断该数是几:(for循环和递归写) 1 1 2 3 5 8 13 21 34
- 一列数的规则如下:1、1、2、3、5、8、13、21、34…… 求第30位数是多少,用递归算法实现。
- 递归实现费氏数列:0,1,1,2,3,5,8,13,21,34,55,89,... ...
- 某数列 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,... 输出此数列第n项值 递归
- 笔试编程题整理1.一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少, 用递归算法实现。
- 一列数的规则如下:1,1,2,3,5,8,13,21,34.....用递归算法求第30位数是多少
- C#实现1 1 2 3 5 8 13 21 34 55...
- 一列数字规则如下:1、1、2、3、5、8、13、21、34..........求第30位数是多少,用递归算法实现?
- C#--第2周实验--任务11--编写一个控制台应用--1列数规则如下:1,1,2,3,5,8,13,21,34...求第30位数是多少?(用递归算法实现)
- 一列数的规则如下:1、1、2、3、5、8、13、21、34......。求第30位数是多少?
- 1、1、2、3、5、8、13、21、34...... 求第X位数是多少,2种实现方式
- 1、1、2、3、5、8、13、21、34...... (用递归算法)
- 关于数列1,1,2,3,5,8,13,21,34..用C#语言编程求第n项为?