从1、2、3、4、5、6这六个数字中任取3个组成三位数,其中能被6整除的有几个 用VB程序怎么编或者任取0-9中的六个数字中再任取3个组成三位数,这种情况怎么编?
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 14:26:55
从1、2、3、4、5、6这六个数字中任取3个组成三位数,其中能被6整除的有几个 用VB程序怎么编或者任取0-9中的六个数字中再任取3个组成三位数,这种情况怎么编?
从1、2、3、4、5、6这六个数字中任取3个组成三位数,其中能被6整除的有几个 用VB程序怎么编
或者任取0-9中的六个数字中再任取3个组成三位数,这种情况怎么编?
从1、2、3、4、5、6这六个数字中任取3个组成三位数,其中能被6整除的有几个 用VB程序怎么编或者任取0-9中的六个数字中再任取3个组成三位数,这种情况怎么编?
Private Sub Form_Click()
Dim i As Long '百位
Dim j As Long '十位
Dim k As Long '个位
Dim s As Long '用来保存生成的三位数
Dim m As Long '统计能被6整除的三位数的个数
Dim n As String '能被6整除的三位数是
For i = 1 To 6
For j = 1 To 6
For k = 1 To 6
If j i And k i And k j Then
s = i * 100 + j * 10 + k '生成一个三位数
If s Mod 6 = 0 Then
m = m + 1
n = n & Str(s) & ","
End If
End If
Next
Next
Next
Debug.Print "能被6整除的三位数的个数是:",m
Debug.Print "能被6整除的三位数分别是:",n
End Sub
-------------------------------------------------
'从9个数字取6个是这样编写(注意下面代码包括百位是0的情况:如036)
Private Sub Form_Click()
Dim a(9) As Long
Dim i As Long
For i = 0 To 9
a(i) = 10
Next
Dim j As Long
Dim k As Long
Dim num As Long
For j = 0 To 5
Randomize '每次执行应用程序时产生不同的随机数列
For k = 0 To 9
num = Int(Rnd * 10)
If num a(k) Then a(j) = num
Next
Next
Dim t As String
For j = 0 To 5
t = t & Str(a(j)) & ","
Next
Debug.Print "随机生成的6个数字是:" & t
Dim l As Long '百位
Dim m As Long '十位
Dim n As Long '个位
Dim s As Long '用来保存生成的三位数
Dim p As Long '统计能被6整除的三位数的个数
Dim q As String
For l = 0 To 5
For m = 0 To 5
For n = 0 To 5
If m l And n l And n m Then
s = a(l) * 100 + a(m) * 10 + a(n) '生成一个三位数
If s Mod 6 = 0 Then
p = p + 1
q = q & Str(s) & ","
End If
End If
Next
Next
Next
Debug.Print "能被6整除的三位数的个数是:",p
Debug.Print "能被6整除的三位数分别是是:",q
End Sub
---------------------------
'从9个数字取6个是这样编写(注意下面代码不包括百位是0的情况:如036)
Private Sub Form_Click()
Dim a(5) As Long '用来存取6个随机数
Dim i As Long '一个循环变量
Dim j As Long '一个循环变量
Dim num As Long '临时存储生成的一个随机数
Dim flag As Boolean
For i = 0 To 5
If i = 0 Then
Randomize
num = Int(Rnd * 10)
a(0) = num保存第一个随机数
Else
Do
flag = False '定义一个标记
Randomize
num = Int(Rnd * 10)
For j = 0 To i - 1
If num = a(j) Then
flag = True
Exit For
End If
Next
If flag = False Then
a(i) = num
Exit Do
End If
Loop
End If
Next
Dim k As String
For i = 0 To 5
k = k & Str(a(i)) & ","
Next
Debug.Print "随机生成的6个数字是:" & k
Dim l As Long '百位
Dim m As Long '十位
Dim n As Long '个位
Dim s As Long '用来保存生成的三位数
Dim p As Long '统计能被6整除的三位数的个数
Dim q As String
For l = 0 To 5
For m = 0 To 5
For n = 0 To 5
If a(l) 0 And m l And n l And n m Then
s = a(l) * 100 + a(m) * 10 + a(n) '生成一个三位数
If s Mod 6 = 0 Then
p = p + 1
q = q & Str(s) & ","
End If
End If
Next
Next
Next
Debug.Print "能被6整除的三位数的个数是:",p
Debug.Print "能被6整除的三位数分别是是:",q
End Sub
'以上3个代码都调试通过,并且3个不同的思路,用了2个多小时完成的,把分给我吧!