VB求前N項和急

時間 2021-08-30 09:52:02

1樓:新新菜鳥手

function sum(byval n as integer) as string

dim i as integer

dim a as double

dim b as integer

b = 1

if n < 2 then

sum = 1

exit function

end if

for i = 2 to n

b = b + i

a = a + cdbl(1 / b)

next i

sum = format(a, "#.0000")end function

private sub command1_click()msgbox sum(6)

end sub

參考這個,希望可以幫到你

2樓:杜守龍

private sub command1_click()dim n as integer, i as integer, mysum as single, p as single

n = val(inputbox("請輸入一個數:"))for i = 1 to n

mysum = mysum + i

p = format((1 / (mysum + i + 1)), "0.0000")

next i

msgbox p

end sub

3樓:匿名使用者

function sum(num as integer)sum=(1+num)*num/2

end function

private sub command1_click()dim i as integer

dim s as double

s=0for i=1 to n

s=s+1/sum(i+1)

next

msgbox round(s,4)

end sub

private sub command2_click()dim i as integer

for i=1 to n

msgbox round(1/sum(i+1),4)end sub

編寫vb程式,求數列的前n項之和:s=2/1+3/2+5/3+8/5+13/8…

4樓:匿名使用者

private sub command1_click()dim n as integer

n = inputbox("輸入n值")

dim a1 as double

dim a2 as double

dim a as double

dim sum as double

a1 = 1

a2 = 1

for i = 1 to n

t = a1 + a2

a1 = a2

a2 = t

a = a2 / a1

sum = sum + a

next i

print "數列前" & n & "項和為" & sumend sub

5樓:匿名使用者

這是數學問題哦,所以程式設計要有一定的數學知識的,要找出通項,在用迴圈做.

規律:分母的n+2項是前兩項的和,分子的n項是分母的n+1項,

先設定第一項和第二項的值,第三項就可以用公式計算了.

6樓:唸尐憂

建立兩個文字框,text1&text2.一個按鈕,command1.

text1為n值.

text2為要求的結果.

command1為計算功能

private sub command1_click()dim a as integer, b as integer, c as integer, i as integer, x as integer, y as integer, z as integer, n as integer, sum as double

n = text1.text

a = 2

b = 3

x = 1

y = 2

select case n

case is = 1

sum = 2

case is = 2

sum = 3.5

case is > 2

sum = 3.5

for i = 3 to n

c = a + b

a = b

b = c

z = x + y

x = y

y = z

sum = sum + c / z

next i

end select

text2.text = sum

end sub

private sub form_load()text1.text = ""

text2.text = ""

end sub

7樓:匿名使用者

三個text , 一個button

private sub command1_click()dim i as integer

dim n as integer

dim dret as double

dim mn as double

dim kn as double

dim t as double

dim s as string

n = text1.text

mn = 2

kn = 1

dret = 0

for i = 1 to n

dret = dret + mn / kns = s & " + " & mn & "/" & knt = mn

mn = mn + kn

kn = t

next i

text2.text = s

text3.text = dret

end sub

vb題用遞迴 方法求數列前n項和 100

8樓:酒瓶裡的蚊子

form1上放一個文字框text1, 一個按鈕command1。

在框中輸入某個數字,例如10,**會將列出f(1)至f(10)的回值。如果你只需要特定的第n項,

答比如第8項,就直接呼叫digui(8)即可。

**:private sub command1_click()dim n as long

n = cint(text1.text)

form1.cls

for n = 1 to 10

print "f(" & cstr(n) & ")=" & digui(n):

next

end sub

private function digui(byval n as integer) as long

select case n

case 1

digui = 0

case 2

digui = 1

case else

digui = 2 * digui(n - 1) - digui(n - 2)

end select

end function

數列求前n項和,求數列前N項和

1.設an a1 n 1 d 1 n 1 d bn b1 q n 1 q n 1 a3 b5 1 2d q 4 21 a5 b3 1 4d q 2 13 聯立 得q 2 4 因為各項為正數。所以q 2 則d 2 an 2n 1 bn 2 n 1 設cn 4n 2 n dn 2 2 n前n項和為cn,...

VB求數列前6項和,VB求數列前6項和

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 病情分析 您好,孩子感冒了,母親要注意食物方面的,清淡一些的,給孩子...

急求等差數列通項公式和前n項和公式的證明方法

通項公式你用數學歸納法證明。前n項和公式也可以用數學歸納法證明。不過建議你採用觀察法 sn a1 a2 a3 ansn an a n 1 a1兩式相加,注意到共有n項,並且對應項均等於a1 an 2 a1 n 1 d,所以 2sn n 2 a1 n 1 d sn n 2 a1 n 1 d 2 解 設...