VB编写程序求S=A!+B!+C!的值
Dim f As Long
Private Sub Command1_Click()
Print "Command1:"
a = Val(InputBox("a="))
b = Val(InputBox("b="))
c = Val(InputBox("c="))
s = fac(a) + fac(b) + fac(c)
Print Trim(a); "!+"; Trim(b); "!+"; Trim(c); "!="; s
End Sub
Function fac(ByVal n As Integer) As Long
Dim s As Long
s = 1
For i = 2 To n
s = s * i
Next i
fac = s
End Function
Private Sub Command2_Click()
Print "Command2:"
f = 0
a = Val(InputBox("a=")): ff (a)
b = Val(InputBox("b=")): ff (b)
c = Val(InputBox("c=")): ff (c)
Print Trim(a); "!+"; Trim(b); "!+"; Trim(c); "!="; f
End Sub
Private Sub ff(n As Integer)
Dim s As Long
s = 1
For i = 2 To n
s = s * i
Next i
f = f + s
End Sub
Dim s, i
s = 1
For i = 1 To n
s = s * i
Next
Getn = s
End Function
Sub abc(a, b, c)
'求S=A!+B!+C!的值
Dim s
s = Getn(a) + Getn(b) + Getn(c)
MsgBox s
End Sub
Private Sub Form_Load()
a = InputBox("请输入A的值")
b = InputBox("请输入B的值")
c = InputBox("请输入C的值")
Call abc(a, b, c)
End Sub
‘由于我电脑上没有安装VB未测试,如有问题请留言
for i as integer = 1 to 自然数
自然数 *=i
next
return 自然数
end function
private sub 计算(sender as object, e as eventargs) handles 计算按钮.click
dim S as integer
Dim A, B, C as integer
'想法赋值
S = 阶乘(a) + 阶乘(b) + 阶乘(c)
msgbox(S)
end sub