1樓:聽不清啊
private sub ***mand1_click()dim n as integer, i as integern = cint(inputbox("n="))for i = 1 to n
s = s + 1 / fact(i)
next i
msgbox ("s=1!+1/2!+1/3!+1/4!+……+1/" & n & "!=" & s)
end sub
function fact(byval n as integer) as double
dim f as double
f = 1
while n > 1
f = f * n
n = n - 1
wend
fact = f
end function
2樓:匿名使用者
private function ss(byval n as integer) as double
dim i as integer
dim t as long
dim s as double
t=1s=0
for i=1 to n
t=t * i
s=s+(1+1/t)
next i
ss =s
end function
編寫一個vb程式,求 1+1/2+1/3+1/4+……+1/n 的值。(測試資料:n=50 答案:4.50)
3樓:匿名使用者
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 sub ***mand2_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 ***mand3_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 ***mand4_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 ***mand5_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
4樓:
^^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
編寫函式sort編寫main函式,呼叫sort函式並輸出排序後的整數
void sort int a,int n main n 10 sort a,n for i 0 i lz要靠計算機 好好努力!要求編寫一自定義函式sort,完成對n個字串的降序排序,然後再main函式中呼叫sort對 beijing shang include include void sort ...
2編寫函式fun,然後設計主函式呼叫函式fun。函式fun的功能是 計算正整數num的各位上的數字之積
int fun int n,int m return sum include void main h fun n,m printf d n h 經過tc和vc 執行後 dao均可出來專正確結屬果 include include int fun int x return r main 1 includ...
用vb編寫函式fun函式的功能是求四位數的各
可以在excel表中的a1 中填寫 1234 在b1 中填寫 power mid a1,1,1 3 power mid a1,2,1 3 power mid a1,3,1 3 power mid a1,4,1 3 這樣就可以得到你想要的值,呵呵 注意以上的 中填寫的雙引號不要加進去哦。functio...