vb編寫fibonacci數列的前20項25項30項按

2021-12-23 03:36:35 字數 2639 閱讀 5961

1樓:

private function fibonacci(byval n as long) as long

if n <= 2 then

fibonacci = 1

else

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

end if

end function

private sub command1_click()dim o as long

for i = 1 to 20

o = o + fibonacci(i)

next

label1 = o

end sub

private sub command2_click()dim o as long

for i = 1 to 25

o = o + fibonacci(i)

next

label1 = o

end sub

private sub command3_click()dim o as long

for i = 1 to 30

o = o + fibonacci(i)

next

label1 = o

end sub

2樓:襖普

private sub command1_click()dim sum as long

for i = 1 to 20

sum = sum + fibonacci(i)next

label1 =sum

end sub

private sub command2_click()dim sum as long

for i = 1 to 25

sum= sum + fibonacci(i)next

label1 = sum

end sub

private sub command3_click()dim sum as long

for i = 1 to 30

sum = sum + fibonacci(i)next

label1 =sum

end sub

如何用vb編寫fibonacci數列前30 項的求和

3樓:名字等於七個字

private sub form_load()dim a(1 to 30) as longdim s as long

me.autoredraw = true

print 1

print 1

a(1) = 1

a(2) = 1

s = 2

for i = 3 to 30

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

s = s + a(i)

next

print "前30項的和為: "; s

end sub

vb中的斐波那契數列 前20項取值總和問題謝謝了,大神幫忙啊

4樓:匿名使用者

斐波那契數列前三項分別是0、1、1,你只加了第二項或第三項 所以才會少1 dim a&(20) a(1) = 0: a(2) = 1 for i = 3 to 20 a(i) = a(i - 2) + a(i - 1) b = a(i) + b next i for i = 1 to 20 print right(space(7) & a(i), 8); if i mod 10 = 0 then print next i b = b + a(2) msgbox b 追問: 我加的是第一項和第二項, 不是加的第二項和第三項,請不要用陣列去給我解答,我還沒學到陣列呢 回答:

dim d as long, a as long, s as long, c as integer d = 0: a = 1: b = 1:

s = 2 print d print a print b for i = 2 to 18 c = a + b a = b: b = c s = s + c print c next i msgbox "斐波拉契數列的錢二十項的和為:" & s, vbinformation, "資訊"

vb求出斐波那契數列的前20項,並按順序將他們顯示在列表框中。

5樓:匿名使用者

單擊窗體後在窗體上輸出前20個斐波那契數(5個一行)private sub frm_click()dim f(20) as integer

f(1)=1

f(2)=1

for i=3 to 20

f(i)=f(i-2)+f(i-1)

next i

for i=1 to 20

if i mod 5=0 then printprint f(i);

next i

end sub

稍改一下吧

用子過程輸出fibonacci數列的前20項及前20項和(vb) 5

6樓:

1.( s )= a + b

2.print ( c )

VB編寫公式

si ni 是什麼,我這裡使用簡單的函式 fs fn 來表示,你可以修改這些函式,實現你需要的功能。private function fs byval i as long as double fs i end function private function fn byval i as long ...

vb編寫程式計算分段函式,VB編寫程式,計算分段函式

在窗體上放一個命令按鈕,將 複製到窗體裡,程式執行單擊一次命令按鈕可輸入一次n的值 如下 private sub command1 click dim n,y as single n inputbox 請輸入n的值 select case n case is 0 y 2 n 5 case 0 y 0...

編寫vb程式,求1編寫一個vb程式,求11213141n的值。測試資料n50答案

private sub mand1 click print 第3題 dim n as integer,s as doublen inputbox n 50 for i 1 to n s s 1 i next i print sum n format s,0.00 end sub private su...