visual basic程序设计教程第四版答案(刘炳文)
VB编程:编写程序,求S=A!+B!+C! 阶乘的计算分别用Sub过程和Function过程两种方法来实现。
解:
1,首先在窗体上画两个命令按钮:Command1 和 Command2
2,然后编写阶乘的Function和Sub过程
'Function过程
Function factF(ByVal n As Integer)
t = 1
For i = 1 To n
t = t * i
Next i
factF = t
End Function
'Sub过程
Sub factS(ByVal n As Integer, fac)
fac = 1
For i = 1 To n
fac = fac * i
Next i
End Sub
3,编写窗体代码
'以下是窗体代码
Dim a As Integer, b As Integer, c As Integer
Private Sub form_load()
Command1.Caption = "调用Function过程"
Command2.Caption = "调用Sub过程"
a = 5
b = 7
c = 9
End Sub
Private Sub command1_click()
Print
Print "调用Function过程时的输出结果:"
Print
s = factF(a) + factF(b) + factF(c)
Print s
End Sub
Private Sub command2_click()
Print
Print "调用Sub过程时的输出结果:"
Print
Dim a1, b1, c1 As Double
factS a, a1
factS b, b1
factS c, c1
s = a1 + b1 + c1
Print s
End Sub
运行此VB源码后,点击两个按钮,结果情况如下图所示:
visual basic 程序设计教程第4版 课后答案 刘炳文 编著
来源:visual basic程序设计教程第四版答案(刘炳文)
本文链接:http://www.wb98.com/vb1/post/vb_9.2.html
本站文章搜索: