1樓:
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
end function
3、計算1!+2!+…+10!的和,並使用msgbox輸出。
dim sum as long,n as longsum=0
for i=1 to 10
n=1for j=1 to i
n=n*j
next j
sum=sum+n
next i
msgbox 「1!+2!+…+10!的和是" & sum4.編寫函式,實現計算n的階乘
private function a(n as integer) as long
dim nn as long
nn=1
for i=1 to n
nn=nn*i
next i
a=nn
end function
5、計算1!+2!+…+99!的和,並使用msgbox輸出。
dim sum as long,n as longsum=0
for i=1 to 99
n=1for j=1 to i
n=n*j
next j
sum=sum+n
next i
msgbox 「1!+2!+…+99!的和是" & sum6、計算1-500之間所有的素數和。
dim i, j, b as integerfor i = 3 to 500
for j = 2 to i - 1
if i mod j = 0 then exit fornext i
if j > i - 1 then b = b + inext i
print b
7、計算1-100之間所有的素數和。
dim i, j, b as integerfor i = 3 to 100
for j = 2 to i-1
if i mod j = 0 then exit fornext i
if j > i - 1 then b = b + inext i
print b
2樓:匿名使用者
你的演算法好麻煩啊……
private sub f1()
dim i, sum, num as doublesum = 0
num = 1
for i = 1 to 99
num = num * i
sum = sum + num
next i
msgbox cstr(sum)
end sub
vb計算1!+2!+3!+…+n!的和
3樓:萌神
private sub command1_click() dim s as double, jc as double, n as integer jc = 1 n = val(inputbox("請輸入n")) for i = 1 to n jc = jc * i s = s + jc next print "s="; s end sub
vb程式設計。輸入整數n,計算1!+2!+3!….+n!的值,並在窗體上輸出。要求分別用for,while 兩種迴圈實現
4樓:落葉l無情
dim i as integer, j as integerdim n as integer, sum as long, jc as long
n = inputbox("請輸入:") '如果是用文字框text1輸入,這裡改為 n=val(text1)
sum = 0
for i = 1 to n
jc = 1
for j=1 to i
jc = jc * j
next j
sum = sum + jc
next i
print sum
while:
dim i as integer, j as integerdim n as integer, sum as long, jc as long
n = inputbox("請輸入:")
sum = 0
i = 1
while i <= n
jc = 1
j = 1
while j <= i
jc = jc * j
j = j + 1
wend
sum = sum + jc
i = i + 1
wend
print sum
用vb程式設計計算:1!+2!+3!+4!+…+n!
5樓:匿名使用者
新建一個工程,新增個命令按鈕和一個文字框
**如下:
private sub command1_click()n = val(text1.text)
s = 0 '存結果
for i = 1 to n
t = 1 '臨時存積的變數
for j = 1 to i '計算階乘
t = t * j
next j
s = s + t
next i
print "結果為:" & s
end sub
VB程式設計作業編寫函式過程,計算
這是樓主要的函式過程 先在窗體上新增一個命令按鈕 private sub command1 click dim n as integer n 100 f nend sub function f n as integer as singledim i as integer for i 1 to n f...
編寫VB程式,計算1! 2 ,編寫VB程式,計算1! 2 3 4 9 10 的值
九條可憐 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 最後...
matlab裡編寫函式實現判斷數是否是質數的
function isprime x if x 2 x 3 disp 這個數是質數 elseif x 1 mod x,2 0disp 這個數不是質數 elseif x 3 result 1 for i 3 2 floor sqrt x if mod x,i 0 result 0 disp 這個數不是...