vb阶乘

时间:2024-09-18 15:49:07编辑:coo君

怎么写vb的阶乘代码

1、For语句实现Private Sub Command1_Click() Dim s As Long, n As Integer, i As Integer n = Val(Text1.Text) s = 1 For i = 1 To n s = s * i Next i Label4.Caption = Str(s)End Sub2、Do While语句实现Private Sub Command1_Click() Dim s As Long, n As Integer, i As Integer n = Val(Text1.Text) s = 1 i = 1 Do While i <= n s = s * i i = i + 1 Loop Label4.Caption = Str(s)End Sub扩展资料:1~10的阶乘的结果如下:1!=12!=2*1=23!=3*2*1=64!=4*3*2*1=245!=5*4*3*2*1=1206!=6*5*4*3*2*1=7207!=7*6*5*4*3*2*1=50408!=8*7*6*5*4*3*2*1=403209!=9*8*7*6*5*4*3*2*1=36288010!=10*9*8*7*6*5*4*3*2*1=3628800

编写VB阶乘的函数

1、vb代码中,求一个数的阶乘的函数代码如下:Public Function jiecheng(ByVal n As Integer) As Double Dim jc As Double jc = 1 For i = 1 To n jc = jc * i Next jiecheng = jc End Function2、具体用法:首先打开VB6.0,新建一个标准exe工程;3、在设计界面上添加一个Command控件,Command1的Caption属性设置为"N的阶乘"。4、双击Command1控件进入代码编辑界面,编辑代码如下:Public Function jiecheng(ByVal n As Integer) As Double Dim jc As Double jc = 1 For i = 1 To n jc = jc * i Next jiecheng = jc End FunctionPrivate Sub Command1_Click()Dim sum As Double, n As Integern = InputBox("计算的N的阶乘,请输入数字N")sum = jiecheng(n)MsgBox (sum)End Sub5、运行新建的工程,单击按钮,输入要计算的N的阶乘的数字N,得出阶乘结果。

上一篇:泡泡战士bug补丁

下一篇:没有了