vb第N項計算出來當然數列,vb求裴波那契數列的第n項

時間 2022-03-08 10:05:15

1樓:匿名使用者

private sub command1_click()if option1.value = true thentext1.text = f(30)

end if

if option2.value = true thentext1.text = f(33)

end if

if option3.value = true thentext1.text = f(35)

end if

end sub

public function f(byval n as integer) as double

dim res as double

if n = 1 or n = 2 thenres = 1

end if

if n = 3 then

res = 2

end if

if n > 3 then

res = f(n - 1) + f(n - 2)end if

f = res

end function

2樓:匿名使用者

private sub form_click()dim a, b, n, s, t as longa = 1

b = 3

n = 2

do while n <= 6

s = s + b

t = a * b

a = b

b = t

n = n + 1

loop

print s

end sub

vb求數列前n項和

vb求裴波那契數列的第n項

3樓:匿名使用者

dim st as string = ""

dim a(100)

a(1) = 0 : a(2) = 1

for i = 3 to 100

a(i) = a(i - 2) + a(i - 1)next i

for i = 1 to 10

st = st & a(i) & " "

if i mod 10 = 0 then st = st & vbcrlf

next i

textbox6.text = st

public function f(byval n as integer) as integer

dim res as integer

if n = 1 or n = 2 thenres = 1

end if

if n = 3 then

res = 2

end if

if n > 3 then

res = f(n - 1) + f(n - 2)end if

return res

end function

vb 斐波那伽數列求第n項和

4樓:徐少

解析://fabonacci數列

1,1,2,3,5,.....

遞推關係式:f(n-2)+f(n-1)=f(n)通項公式:

vb 程式設計輸出fibonacci數列的前n項

5樓:娛樂小八卦啊

這題主要考察遞迴函式的思想。**如下:

#include

int  fbi(int i);//遞迴函式:輸出數列的第i項資料,這裡i從0開始計算。

int main()

else

}擴充套件資料

乙個函式可以呼叫其他函式。如果這個函式在內部呼叫它自己,那麼這個函式就叫遞迴函式。遞迴函式的作用和迴圈的方法效果一樣,即遞迴函式本質上是乙個方法的迴圈呼叫,注意:

有可能會出現死迴圈。因此,使用遞迴函式時,一定要定義遞迴的邊界(即什麼時候退出迴圈)。

注意:在實際使用中,遞迴函式由於消耗時間比較長(相比for迴圈和while迴圈),所以很少使用。要使遞迴函式有用,則遞迴函式必須有乙個方法來控制遞迴呼叫的次數。

每次函式呼叫自己時,迴圈都會重複。現在應該能發現該函式的問題,因為它沒有辦法停止遞迴呼叫。這個函式就像乙個無限迴圈,因為沒有**阻止它重複。

6樓:匿名使用者

private sub form_load()dim i as integer

form1.autoredraw = truefor i = 1 to 10

print fibonacci(i);

next i

end sub

private function fibonacci(byval n as integer) as long

dim f(32767) as long

if n = 1 or n = 2 thenfibonacci = 1

else

fibonacci = fibonacci(n - 1) + fibonacci(n - 2)

end if

end function

另外也可以用通項公式求得。如**。

7樓:風行少年

private sub form_click()dim l1 as long, l2 as long, l3 as long, f as long, n as integer

l1 = 1: l2 = 1

for n = 1 to 40

if n <= 2 then

f = 1

print f

else

l3 = l1 + l2

l1 = l2

l2 = l3

print l3

end if

next n

end sub

根據之前一版改的,因為當時還沒複習到函式和陣列,這個程式比較符合當的情境,其實有好幾種方法。

市盈率怎麼計算出來,市盈率是怎麼算出來的?

市盈率 股價 年度每股盈餘 eps 計算時,股價通常取最新 價,而eps方面,若按已公布的上年度eps計算,稱為歷史市盈率 historical p e 計算預估市盈率所用的eps預估值,一般採用市場平均預估 consensus estimates 即追蹤公司業績的機構收集多位分析師的 所得到的預估...

每股收益是怎麼計算出來的

清飛楊 每股收益 當期累計完成的淨利潤 總股本。理論上每股收益越高,股東的分紅就越高,但事實上董事會要考慮公司的未來發展,同時,國有企業的分紅還要考慮國家利益,所以,有時每股收益高,並不就是分紅高。但收益高,分紅也高是總體的趨勢。每股收益即每股盈利 eps 又稱每股稅後利潤 每股盈餘,指稅後利潤與股...

怎麼計算出來的,怎麼算出來的?那些數字怎麼算出來的?

1710.53萬元。2013年7月購入,購入當月起即開始攤銷,2013年合計攤銷6個月,2013年累計攤銷 2000 10 6 12 100,2013年末賬面價值 2000 100 1900萬元,由於當日可收回金額1800萬元小於1900萬元,應當計提100萬元的減值準備,將賬面價值調整至1800萬...