1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
Dim total1 As String
Public Function Komb1(ByVal tableau, ByVal Prefixe As String, ByVal min As Integer, ByVal max As Integer, ByVal n As Integer) As String
Dim i As Integer
Dim Resultat As String
For i = min To max - n + 1
If Prefixe = "-1" Then
Resultat = tableau(i)
Else
Resultat = Prefixe & "*" & tableau(i)
End If
If n > 1 Then
Komb1 tableau, Resultat, i + 1, max, n - 1
Else
If total1 = vbNullString Then
total1 = Resultat
Else
total1 = total1 & "+" & Resultat
End If
End If
Next
Komb1 = total1
End Function
Sub Main()
Dim tableau() As Variant
Dim max As Integer
Dim min As Integer
max =4
min = 3
ReDim tableau(0 To max - 1)
For i = 1 To max
tableau(i - 1) = Chr(64 + i)
Next i
MsgBox Komb1(tableau, -1, 0, max - 1, min)
end sub |
Partager