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 Sub
2、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!=1
2!=2*1=2
3!=3*2*1=6
4!=4*3*2*1=24
5!=5*4*3*2*1=120
6!=6*5*4*3*2*1=720
7!=7*6*5*4*3*2*1=5040
8!=8*7*6*5*4*3*2*1=40320
9!=9*8*7*6*5*4*3*2*1=362880
10!=10*9*8*7*6*5*4*3*2*1=3628800
在画面添悔尘加判前纯Text1和Command1Private Sub Command1_Click()
Dim i As Integer
Dim dSum As Double
dSum = 1
For i = 1 To Val(Text1.Text)
dSum = dSum * i
Next
MsgBox dSum
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)