作业帮 > 综合 > 作业

急.0~9十位数的全排列.10位中不有重复的数字

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/14 06:18:03
急.0~9十位数的全排列.10位中不有重复的数字
3628800组.
急.0~9十位数的全排列.10位中不有重复的数字
Option Explicit
Dim A(9) As Integer
Dim I As Integer
Dim C As Double,S As String
Private Sub Form_Load()
A(0) = 0 '++标记
Do While A(0) < 10
A(1) = 0
Do While A(1) < 10
If notCf(A(),1) Then
A(2) = 0
Do While A(2) < 10
If notCf(A(),2) Then
A(3) = 0
Do While A(3) < 10
If notCf(A(),3) Then
A(4) = 0
Do While A(4) < 10
If notCf(A(),4) Then
A(5) = 0
Do While A(5) < 10
If notCf(A(),5) Then
A(6) = 0
Do While A(6) < 10
If notCf(A(),6) Then
A(7) = 0
Do While A(7) < 10
If notCf(A(),7) Then
A(8) = 0
Do While A(8) < 10
If notCf(A(),8) Then
A(9) = 0
Do While A(9) < 10
If notCf(A(),9) Then
S = ""
For I = 0 To 9
S = S + Trim(A(I))
Next
C = C + 1
Debug.Print C,S
End If
A(9) = A(9) + 1
Loop
End If
A(8) = A(8) + 1
Loop
End If
A(7) = A(7) + 1
Loop
End If
A(6) = A(6) + 1
Loop
End If
A(5) = A(5) + 1
Loop
End If
A(4) = A(4) + 1
Loop
End If
A(3) = A(3) + 1
Loop
End If
A(2) = A(2) + 1
Loop
End If
A(1) = A(1) + 1
Loop
A(0) = A(0) + 1
Loop
End Sub
Function notCf(M() As Integer,N As Integer) As Boolean
Dim J As Integer
For J = 0 To N - 1
If M(J) = M(N) Then
notCf = False
Exit For
Else
notCf = True
End If
Next
End Function
'结果:第一位数不是零时共有362880种.第一位允许为零时,则有3628800种.
'本程序是允许第一位是零的.若不允许第一位为零,可将"++标记"句改为A(0) =1 即可.
'本程序是显示在立即窗口中,也可以文件方式存盘.
以上程序已经在我的电脑上运行过.