有M个0,1的排列,这个排列通过程序打印出来。如有3个0,1的排列,应打出:
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
这该怎样生成,请高手帮忙,先谢了!对了,M的取值不是事先知道的,可以临时改变。
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
这该怎样生成,请高手帮忙,先谢了!对了,M的取值不是事先知道的,可以临时改变。
比如你输入5,先得出5个1的二进制为31,(自己解决)
然后:
写一个将10进制转成二进制的函数,比如:
Public Function DecToBinary(dec As Integer)
Dim m As String, n As String, d As Integer
d = dec
Do
m = (d Mod 2) & m
d = d \ 2
Loop Until d = 0
DecToBinary = m
End Function然后再:
dim i as Integer
dim s as string
for i=0 to 31
s=str(DecToBinary(i))
print s & vbcrlf
next i
a(0)=0 a(1)=0 a(2)=0
a(0)=0 a(1)=0 a(2)=1
.
.
.
a(0)=1 a(1)=1 a(2)=1
希望能得到这样的结果。
ReDim ABuf(2 ^ M - 1, M - 1)
Dim iRow As Integer
Dim iCol As Integer
Dim iNum As Integer
For iRow = 0 To 2 ^ M - 1
iNum = iRow
For iCol = M - 1 To 0 Step -1
ABuf(iRow, iCol) = iNum Mod 2
iNum = iNum \ 2
Next iCol
Next iRow
End SubPrivate Sub Command1_Click()
Dim A() As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
k = InputBox("输入M的值")
CreateArray k, A
For i = 0 To 2 ^ k - 1
For j = 0 To k - 1
Debug.Print A(i, j);
Next j
Debug.Print
Next i
End Sub
Dim M, a() As Integer, i, P
M = 4: ReDim a(M - 1)
Do
P = M - 1
For i = 0 To P
Debug.Print a(i);
Next: Debug.Print
Do
a(P) = a(P) + 1
If a(P) > 1 Then a(P) = 0: P = P - 1 Else Exit Do
Loop While P > -1
Loop While P > -1
1: 数据库 文本文件也可以当成数据库操作
2:把数据加到LISTVIEW 或者 list中
Sorted 属性 返回一个值,指定控件的元素是否自动按字母表顺序排序。