1樓:匿名使用者
(1)用sub實現的過程bai
如下:du
dim a,b,c,s
a=1b=2
c=3s=0
sub jc(x)
dim v
v=1while x>0
v=v*x
x=x-1
wend
s=s+v
end sub
jc a
jc b
jc c
msgbox s
(2)用function的過程zhi如下
function
function jc(a)
if a>0 then
jc=a*jc(a-1)
else
jc=1
end if
end function
dim s,a,b,c
a=4b=7
c=5s=jc(a)+jc(b)+jc(c)
2樓:網海1書生
:private sub ***mand1_click()
dim a as long, b as long, c as long
a = val(inputbox("請輸入一個大於0的整數a:"))
b = val(inputbox("請輸入一個大於0的整數b:"))
c = val(inputbox("請輸入一個大於0的整數c:"))
if a > 0 and b > 0 and c > 0 then
n1 a
n1 b
n1 c
msgbox "a!+b!+c!=" & a + b + c
end if
end sub
sub n1(n as long)
dim i as long, s as long
s = 1
for i = 2 to n
s = s * i
next
n = s
end sub
function實現:
private sub ***mand1_click()
dim a as long, b as long, c as long
a = val(inputbox("請輸入一個大於0的整數a:"))
b = val(inputbox("請輸入一個大於0的整數b:"))
c = val(inputbox("請輸入一個大於0的整數c:"))
if a > 0 and b > 0 and c > 0 then
msgbox "a!+b!+c!=" & n2(a) + n2(b) + n2(c)
end if
end sub
function n2(n as long) as long
dim i as long
n2 = 1
for i = 2 to n
n2 = n2 * i
next
end function
請注意:輸入的數字不能太大,因為受long型最大值的限制,計算13!即溢位。要想計算更大的數值,可使用double數值型別
用VB編寫程式,用VB編寫一個程式
樓上的,不許要引用吧 option explicit private declare function getdrivetype lib kernel32 alias getdrivetypea byval ndrive as string as long private declare funct...
求VB高手 編寫程式,找出10000 99999的所有迴文數
private sub mand1 click dim i as long,j as longdim x1 as long,x2 as longdim str as string dim flag as boolean str 從 10000 到 99999 之間的迴文數有 vbcrlf for i...
用c語言編寫程式,求s1,用C語言編寫程式,求S11223nn1,直到最後一項的絕對值小於
只求從bai第二項起的浮點du 和,把第一項1作為初值zhi直接賦給和dao變數s。如內下 include stdio.h int main int argc,char argv 執行結果如下 最後一項的絕對值小於10的幾次方呀 最後問題顯示沒顯示完整 include stdio.h double ...