1樓:匿名使用者
這是樓主要的函式過程(先在窗體上新增一個命令按鈕)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 = f + 1 / i
next i
print "1+1/2+1/3+…+1/100結果為:" & fend function
2樓:匿名使用者
dim i
dim sum=0
for i=1 to 100
sun=sum+1/i
next
大概就應該是這樣的,我沒有實際測試過,不過也十不離**了。
3樓:
private sub command1_click()dim n as double
dim sum as double
for n = 1 to 100 + 1
sum = sum + 1 / n
next
text1.text = str(sum)end sub
vb利用迴圈結構程式設計計算表示式1+1/2+1/3+.....+1/n的值
4樓:數學與計算機程式設計
private sub command1_click()static n as long, valsum as doubleselect case command1.captioncase "計算"
valsum = 0
dim i as long
n = inputbox("pleace input integer n:", "inputbox", 10)
command1.caption = "顯示"
for i = 1 to n
valsum = valsum + 1 / inext i
case "顯示"
label1.caption = "n=" + cstr(n)text1.text = valsum
command1.caption = "計算"
end select
end sub
private sub form_load()text1.enabled = falsetext1.text = ""
command1.caption = "計算"
command1.fontbold = truecommand1.fontsize = 22command1.fontname = "宋體"
text1.fontname = "times new roman"
text1.fontbold = truetext1.fontsize = 22
end sub
vb 中編寫函式fun(n),計算s=1+1/2!+1/3!+....+1/n!怎麼寫**。求幫忙補空。
5樓:宜之槐慎卿
樓主把vb和c混了
看看這個
function
fun(byvalnas
integer)
assingle
dimi,tas
integer
dims
assinglet=
1fori=
1tont
=t*i
s=s+
1/tnext
ifun=s
endfunction
注意,呼叫
是n不能太大了,否則就得改
dimt
aslong
6樓:鍾離茹雲茅曄
你提供的**有問題,應該如此:
function
fun(byvalnas
integer)
assingle
dimi,j,t
asinteger:dimsas
single
s=1for
j=2to
nt=1
fori=2ton
t=t*i
next
is=s+
1/tnext
jfun=
send
function
編寫一個vb程式,求 1+1/2+1/3+1/4+……+1/n 的值。(測試資料:n=50 答案:4.50)
7樓:匿名使用者
private sub command1_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 sub command2_click()print "第4題:";
dim n as integer, s as doublen = inputbox("n=", , 50)for i = 1 to n
s = s + (-1) ^ (i - 1) * (1 / i)next i
print "sum(" & n & ")="; format(s, "0.00")
end sub
private sub command3_click()print "第5題:";
dim n as integer, s as doublen = inputbox("n=", , 20)for i = 1 to n
for j = 1 to i
s = s + j
next j
next i
print "sum(" & n & ")="; send sub
private sub command4_click()print "第6題:";
dim n as integer, s as doublen = inputbox("n=", , 50)for i = 1 to n
if i mod 3 = 0 or i mod 7 = 0 thens = s + i
end if
next i
print "sum(" & n & ")="; send sub
private sub command5_click()print "第7題:";
dim n as integer, s as doublen = inputbox("n=", , 10)s = 1
for i = 1 to n
s = s * i
next i
print n & "!="; s
end sub
8樓:
^^private sub form_click()dim i as integer
dim x as single
for i = 1 to 50
x = x + 1 / i
next
print x
end sub
private sub form_click()dim i as integer
dim x as single
for i = 1 to 50
x = x + (-1) ^ (i - 1) / inext
print x
end sub
函式遞迴
private sub form_click()print f(50)
end sub
public function f(x as integer) as single
if x > 1 then
f = f(x - 1) + (-1) ^ (x + 1) / xelse
f = 1
end if
end function
vb60程式設計作業,VB6 0程式設計作業
第一題 dim i as integer do i i 1 if i mod 2 1 and i mod 3 2 and i mod 4 3 and i mod 5 4 and i mod 6 5 and i mod 7 0 then exit do loop msgbox 共有 i 階 vb6.0...
vb程式設計中關於inputbo函式
刺友互 1 開啟一個excel的檔案,在 中輸入簡單的 比如衣服輸入資料的 2 接著,滑鼠左鍵單擊 開發工具 選單標籤,在vba控制元件下拉選單中,並選擇表單按鈕控制元件。3 然後,在 中繪製出按鈕控制元件,並修改按鈕控制元件名稱,比如輸入名稱,並滑鼠左鍵單擊 檢視 按鈕。4 接著,在彈出的在 視窗...
用VB程式設計隨機抽取姓名,用vb編寫了這個隨機抽取人名的程式,要求一個文字框,一個按鈕
60個人的記錄,把隨機函式控制成小於等於60 private type student name as string 10 end type private sub command1 click 寫入資料dim stu as student open d student.txt for random...