vb從數中仰能滿足條件的數的所有組合

時間 2021-05-07 20:00:33

1樓:

dim x&(6), s&

private sub command1_click()x(0) = 0

open "answer.xls" for output as #1getnum 1 '選出第1個數

close #1

unload me

end sub

function getnum(k&) '遞迴選出第k個數子程式for x(k) = x(k - 1) + 1 to 33 '保證選出第k個數比前1個數大

if k = 6 then '選出6個數之和是否等於一個特定數

s = s + x(k) '選出的6個數之和if s = 100 then '記錄結果print #1, x(1) & chr(9);

print #1, x(2) & chr(9);

print #1, x(3) & chr(9);

print #1, x(4) & chr(9);

print #1, x(5) & chr(9);

print #1, x(6)

end if

s = s - x(k) '去掉最後1個數else

s = s + x(k) '選出的k個數之和k = k + 1 '累計選出的個數之和getnum k '遞迴選出第k個數end if

next

k = k - 1 '回溯s = s - x(k) '去掉最後1個數end function

2樓:

只能滿足條件一的前十個結果

public class form1

private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.

click

dim result as string = ""

dim count as integer = 0for i as integer = 1 to 33for j as integer = 1 to 33for k as integer = 1 to 33for l as integer = 1 to 33for m as integer = 1 to 33for n as integer = 1 to 33if i + j + k + l + m + n = 100 then

if count = 10 then goto markcount += 1

result += i & "+" & j & "+" & k & "+" & l & "+" & m & "+" & n & "=100" & vbcrlf

end if

next

next

next

next

next

next

mark:

textbox1.text = resultend sub

end class

將數字1-33 任選出6個數進行組合,請問excel公式是什麼?

3樓:匿名使用者

如果要6個數沒有重複而且各數字出現概率相等的話,直接設公式有些複雜,需要一個輔助列

a1=rand()

下拉到a33

b1=rank(a1,$a$1:$a$33)下拉到b6

b1-b6就是選出的數字

4樓:匿名使用者

也就是用&把randbetween串起來,當然,橫槓只是分隔符,你可以換別的

VB怎麼從1 8中取數,VB怎麼從1 8中取6個數

private sub command1 click for i1 1 to 8 for i2 i1 1 to 8 for i3 i2 1 to 8 for i4 i3 1 to 8 for i5 i4 1 to 8 for i6 i5 1 to 8 s i1 i2 i3 i4 i5 i6if in...

從10到4999這自然數中其數字和能被4整除的

付啟恆 答案 1246 分析 這樣的數一個一個地找起來實在太麻煩,要想辦法把它們配起對來 詳解 對於每一個三位數 來說,在1 2 3 和4 這4個數中恰好有1個數的數字和能被4整除 所以從1000到4999這4000個數中,恰有1000個數的數字和能被4整除 同樣道理,我們可以知道600到999這4...