Dim cn() As String Dim cs As Integer Dim cx() As Integer Dim a() As Integer Dim x() As IntegerSub pb() cs = InputBox("请输入元素的个数:") ReDim cn(cs) ReDim a(cs) ReDim x(cs) For I = 1 To cs cn(I) = InputBox("请输入第" & I & "个元素。") Next End Sub Sub try(I As Integer) Dim j As Integer DoEvents For j = 1 To cs If a(j) = 0 Then x(I) = j a(j) = 1 If I < cs Then try (I + 1) Else For t = 1 To cs If t < cs Then Debug.Print cn(x(t)) & " "; Else Debug.Print cn(x(t)) End If Next End If a(j) = 0 End If Next End Sub Private Sub Form_Load() pb try (1) End Sub
对于第一题,题目有些不清不楚,如下是我的解答,不知是否合你的题意?Function f(n As Integer, p As Integer) As Long f = n * p End Function Function sum(n As Integer) As Long Dim i As Integer sum = 1 For i = 1 To n sum = sum + f(i, p) Next End Function
Dim cs As Integer
Dim cx() As Integer
Dim a() As Integer
Dim x() As IntegerSub pb()
cs = InputBox("请输入元素的个数:")
ReDim cn(cs)
ReDim a(cs)
ReDim x(cs)
For I = 1 To cs
cn(I) = InputBox("请输入第" & I & "个元素。")
Next
End Sub
Sub try(I As Integer)
Dim j As Integer
DoEvents
For j = 1 To cs
If a(j) = 0 Then
x(I) = j
a(j) = 1
If I < cs Then
try (I + 1)
Else
For t = 1 To cs
If t < cs Then
Debug.Print cn(x(t)) & " ";
Else
Debug.Print cn(x(t))
End If
Next
End If
a(j) = 0
End If
Next
End Sub
Private Sub Form_Load()
pb
try (1)
End Sub
f = n * p
End Function
Function sum(n As Integer) As Long
Dim i As Integer
sum = 1
For i = 1 To n
sum = sum + f(i, p)
Next
End Function