編寫VB程式,計算1! 2 ,編寫VB程式,計算1! 2 3 4 9 10 的值

時間 2021-05-07 20:00:43

1樓:九條可憐

function jc(a) '階乘計算,自定義函式if a = 0 then

jc = 1'規定0!=1。數學上的

else

i = 1'不能等於0,任何數乘以0都等於0,最終答案是0jc = 1'不能等於0,任何數乘以0都等於0,最終答案是0while i <= a'如果i<=a,那麼執行迴圈體jc = jc * i'最後的結果是jc=i!

i = i + 1'i的值遞增

wend'結束迴圈

end if

end function'退出函式自定義

private sub form_load()'載入窗體執行**for i = 1 to 10'讓i的值從1遞增到10,並且遞增一次執行一次**

s = s + jc(i)'使用剛才定義的「階乘計算」jc()函式計算i的階乘,並計算與s的和

next'結束i的遞增

msgbox s'輸出結果

end sub

2樓:施流逸

sum =0

for i=1 to 10

jc=1

for j=1 to i

jc=jc*j

next

if i mod 2 =0 then

sum=sum-jc

eles

sum=sum+jc

end if

next

print sum '結果在sum中

vb編寫程式計算1+2!+3!+4!+……+10!的程式

3樓:匿名使用者

function jc(n as integer) as longdim i%

jc = 1

for i = 1 to n

jc = jc * i

next

end function

private sub command1_click()dim sumadd as long, i%for i = 1 to 10

sumadd = sumadd + jc(i)next

print sumadd

end sub

4樓:匿名使用者

private sub form_click()s = 1

for i = 2 to 10

s = s + jiecheng(i)

next i

print s

end sub

function jiecheng(a)

t = 1

for i = 2 to a

t = t * i

next i

jiecheng = t

end function

用vb程式編寫一個過程來計算1+2+3+4+……+100的值。

5樓:因特兒

private sub command1_click()dim sum as integer '定義變數sum,i為整形dim i as integer

sum=0'給sum賦值

for i = 1 to 100 』for迴圈sum = sum + i '迴圈過程每次給sum加一next i

print sum 』輸出sum和

end sub

6樓:匿名使用者

dim a as integer '首項

dim b as integer '末項

dim c as integer '項數

dim d as integer '結果

public sub add()

a = inputbox("首項", "")b = inputbox("末項", "")c = inputbox("項數", "")d = (a + b) * c / 2

msgbox d

end sub

private sub form_load()call add

end sub

針對這個問題首項=1,末項=100,項數=100end sub

7樓:

private sub button1_click()dim i as integer, j as integerj = 0

for i = 1 to 100

j += i

next i

msgbox(j)

end sub

vb程式設計題 求1!+2!+3!+4!+...+10!的值。求大神詳細的對的。

8樓:慶年工坊

sub s()

dim i%, st&, sm&

st = 1

for i = 1 to 10

st = st * i

sm = sm + st

next

print sm

end sub

用vb程式設計計算:1!-2!+3!-4!+…-10! 這個**是什麼?

9樓:匿名使用者

1!-2!+3!-4!+…-10!=1-2*1+3*2*1-4*3*2*1+…-10*9*8*7*6*5*4*3*2*1=?

看到規律沒?

用兩個巢狀的for

for i=1 to 10

s=0for j=1 to i

s=s*j*(-1)^(i+1)

end for

t=t+s

end for? t

vb:用函式實現1+2!+3!+4!+......+10!

10樓:

private sub form_click()dim i, j as integer

dim temp, answer as doublefor i = 1 to 10

temp = 1

for j = i to 1 step -1temp = temp * j

next j

answer = answer + tempnext i

print "答案為:" & answerend sub

11樓:伊人尤在

private function factor_sum(n as integer) as integer

factor_sum=0

for i=1 to n

f=1for j=1 to i

f=f*j

next j

factor_sum=factor_sum+fnext i

end sub

呼叫時:

result=factor_sum(10)或 print factor_sum(10)即可.

vb程式設計計算1 1/2!-1/3! 1/4!-1/5!的值

12樓:

private sub command1_click()dim f as double

dim i as integer

dim sign as integer

f = 1

sign = 1

for i = 2 to 5

sign = -sign

f = f + sign * 1 / fac(i)next i

print "1+1/2!-1/3!+1/4!-1/5! ="; fend sub

function fac(n as integer) as longdim i as integer

fac = 1

for i = 2 to n

fac = fac * i

next

end function

vb編寫函式,實現計算1 2n

private function a n as integer as long dim sum as long,nn as integer,i,jsum 0 for j 1 to n nn 1 for i 1 to j nn nn i next i sum sum nn next j a sum e...

vb,編寫程式計算1 2100,請高手幫忙糾錯

修改以後的程式如下,已經執行通過,答案正確 private sub form click dim i as integer dim sum as integer for i 1 to 100 sum sum i next i print sum end sub 在for迴圈的內部不能再用i i 1 ...

vb定時執行,VB編寫自動執行程式

你可以用一個timer控制元件完成 取現行時間等於某一個你想要的值時候 執行command1的單擊命令 timer1的interval設為1000。private sub timer1 timer dim t as date dim m as integer,s as integert time m...