输入n,输出1~n所有数的排列方法
答案:1 悬赏:10 手机版
解决时间 2021-05-07 13:41
- 提问者网友:相思似海深
- 2021-05-07 06:23
用qbasic做。
最佳答案
- 五星知识达人网友:骨子里都是戏
- 2021-05-07 07:18
Sub Swaps( a, b )
t = a : a = b : b = t
End Sub
Sub per( a(), ByVal k, ByVal n )
If k = n Then
For i = 0 To n
Print a(i);
Next
Print
Else
For i = k To n
Swaps( a(i), a(k) )
per( a(), k+1, n )
Swaps( a(i), a(k) )
Next
EndIf
End Sub
Input "Enter n:", n
Dim a(0 To n-1)
For i = 0 To n-1
a(i) = i+1
Next
per( a(), 0, n-1 )
t = a : a = b : b = t
End Sub
Sub per( a(), ByVal k, ByVal n )
If k = n Then
For i = 0 To n
Print a(i);
Next
Else
For i = k To n
Swaps( a(i), a(k) )
per( a(), k+1, n )
Swaps( a(i), a(k) )
Next
EndIf
End Sub
Input "Enter n:", n
Dim a(0 To n-1)
For i = 0 To n-1
a(i) = i+1
Next
per( a(), 0, n-1 )
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯