1樓:科技程式迷
理論來說下面的**沒有錯,但是我也不明白為什麼不行:
private sub form_load()
dim a as integer, b as integer, c as integer, temp as long, s as double
dim n as integer
temp = 1
c = 1 'c這個變數當a是奇數時為1否則為-1,由iif()語句控制值得變化
n = val(inputbox("請輸入n的數值", "輸入n值", "20"))
for a = 1 to n
for b = 1 to a
temp = temp * b
'msgbox "b=" & b
next
msgbox "s=" & s
s = s + c \ temp
c = iif(c = 1, c = -1, c = 1) '這句因該能夠理解吧,如果當c=1是c就取-1,反之亦反
temp = 1
next
msgbox "s= " & s 'format(s, "#.######")
end sub
請高手一起解決該問題。
編vb程式計算1-1/2!+1/3!-1/4!+···+(-1)^(n-1)*(1/n!)的和?
2樓:匿名使用者
private sub form_click()dim i as long, p as double, s as double, t as integer
t = 1
p = 1
dim n as integer
n = inputbox("請輸來入
源一個整數:")
for i = 1 to n
p = p * i
s = s + t / p
t = -t
next
print format(s, "0.0000000")end sub
3樓:匿名使用者
private sub ***mand1_click()dim s as single
dim n as integer
n = val(text1)
for i = 1 to n
s = s + (-1) ^ (n - 1) * 1 / nnext
print "s = "; s
end sub
vb試題程式設計計算1-1/2+1/3-1/4+...+1/99-1/100
4樓:
1:dim i as integer
dim s as double
dim s0 as double
for i = 1 to 100
s0 = 1 / i
if i mod 2 = 0 then s0 = s0 * (-1)s = s + s0
next
print s
2:dim i as integer
dim s as double
for i = 1 to 100 step 2s = s + 1 / i - 1 / (i + 1)next
print s
3:dim i as integer
dim s as double
i = 1
do until i >= 100
s = s + 1 / i - 1 / (i + 1)i = i + 2
loop
print s
4:dim i as integer
dim s as double
for i = 1 to 100
select case i mod 2
case 0
s = s - 1 / i
case 1
s = s + 1 / i
end select
next
print s
計算e=1-1!+1/2!-1/3!+1/4!……,直到最後一項的絕對值<1e-4 的c語言程式設計 25
5樓:冷葉憶雪
看**:
#include
#define eps 1e-4
int main(int argc, char** argv)e += sign * tmp;
++n;
sign = -sign;
}printf ("%lf\n", e);
return 0;}
寫程式計算並輸出下列多項式值: sn = 1 + 1/1! + 1/2! + 1/3! + 1/4! + ... + 1/n!
6樓:匿名使用者
void main()
cout<
7樓:成殤
#include
double fun(int n)
return sn;
}void main()
用vb編寫程式,計算
option explicitdim k,t as singleprivate sub mand1 click for k 2 to 300 step 2t t 1 k next label1.caption t end sub for i 2 to 300 step 2 sum 1 i sum n...
VB程式設計題目,vb程式設計題目
private sub command1 click dim k sum sum 0 k val trim inputbox 請輸入正整數k的值 for i 1 to len str k sum sum val mid str k i,1 next i msgbox sum end subpriva...
VB的程式開發步驟?VB程式設計一般的四個步驟
visual basic vb 程式開發的步驟如下 設計 制定程式的流程圖和介面設計。建立專案 使用 visual studio 建立一個新的 visual basic 專案,並選擇合適的模板。編寫 編寫程式的主要 邏輯。測試 使用 visual studio 內建的除錯功能對程式進行測試,確保程式...