用VB编写程序, 求s=a!+b!+c!,阶乘的计算分别用SUB过程和Function过程两种方法实现!!!

VB编写... VB编写 展开
 我来答
雨雪霏霏cuihi
推荐于2017-12-15 · TA获得超过4万个赞
知道大有可为答主
回答量:4854
采纳率:50%
帮助的人:4187万
展开全部
1,

Dim a,b,i
a=Array(2,8,7,6,4,28,70,25)
b=Array(79,27,32,41,57,66,78,80)

Dim c(8)

For i=0 To Ubound(a)
c(i)=a(i)+b(i)
Next

2
1)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=4
b=7
c=5
s=jc(a)+jc(b)+jc(c)

2)Sub

Dim a,b,c,s

a=1
b=2
c=3
s=0

Sub jc(x)
Dim v
v=1
While x>0
v=v*x
x=x-1
Wend
s=s+v
End Sub

jc a
jc b
jc c

MsgBox s

另一种方法:

Function x(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer)
suma = 1
sumb = 1
sumc = 1
For i = 1 To a
suma = suma * i
Next
For j = 1 To b
sumb = sumb * j
Next
For k = 1 To c
sumc = sumc * k
Next
x = suma + sumb + sumc
Print "调用Function过程时的输出结果:"
End Function

Private Sub Command1_Click()
Dim a(2) As Integer
For i = 0 To 2
a(i) = InputBox("输入第" & i + 1 & "个数")
Next
Print x(a(0), a(1), a(2))
End Sub

Sub y(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer)
suma = 1
sumb = 1
sumc = 1
For i = 1 To a
suma = suma * i
Next
For j = 1 To b
sumb = sumb * j
Next
For k = 1 To c
sumc = sumc * k
Next
Sum = suma + sumb + sumc
Print "调用Sub过程时的输出结果:"
Print Sum
End Sub

Private Sub Command2_Click()
Dim a(2) As Integer
For i = 0 To 2
a(i) = InputBox("输入第" & i + 1 & "个数")
Next
y a(0), a(1), a(2)
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式