一道VB题目
OptionBase1PrivateSubCommand1_Click()Dimn1AsInteger,b()AsInteger,kAsIntegerRandomizeP...
Option Base 1
Private Sub Command1_Click()
Dim n1 As Integer, b() As Integer, k As Integer
Randomize
Picture1.Cls
n1 = Int((Rnd * 90) + 10)
Call sub1(b, n1)
s2 = b(1) * 10 + b(2)
k = 9
Do
Call sub1(b, k)
s1 = b(1) * 10 + b(2)
If n1 + k = s2 + s1 Then
Picture1.Print n1; "+"; k; "="; s1; "+"; s2
End If
k = k + 1
Loop Until k = 100
End Sub
Public Sub sub1(d() As Integer, k As Integer)
ReDim d(2)
d(1) = k Mod 10
d(2) = k \ 10
End Sub
谁能帮我解释一下程序啊?
程序结果如图,主要是将一个2位数,它的个位与十位对调后,产生另一个正整数,再找出另一对2位正整数,使得这两个正整数之和等于它们对调后数之和。例如:12+32=23+21
要详细一些啊? 展开
Private Sub Command1_Click()
Dim n1 As Integer, b() As Integer, k As Integer
Randomize
Picture1.Cls
n1 = Int((Rnd * 90) + 10)
Call sub1(b, n1)
s2 = b(1) * 10 + b(2)
k = 9
Do
Call sub1(b, k)
s1 = b(1) * 10 + b(2)
If n1 + k = s2 + s1 Then
Picture1.Print n1; "+"; k; "="; s1; "+"; s2
End If
k = k + 1
Loop Until k = 100
End Sub
Public Sub sub1(d() As Integer, k As Integer)
ReDim d(2)
d(1) = k Mod 10
d(2) = k \ 10
End Sub
谁能帮我解释一下程序啊?
程序结果如图,主要是将一个2位数,它的个位与十位对调后,产生另一个正整数,再找出另一对2位正整数,使得这两个正整数之和等于它们对调后数之和。例如:12+32=23+21
要详细一些啊? 展开
2个回答
展开全部
Option Base 1 ==> 定义数组基数从1开始
Private Sub Command1_Click()
Dim n1 As Integer, b() As Integer, k As Integer
Randomize ==> 产生随机系列
Picture1.Cls
n1 = Int((Rnd * 90) + 10) ==> 得到一个10到99的随机数赋给n1
Call sub1(b, n1) ==> 得到数组b,第一个元素是n1的个位,第二个元素是n1的十位
s2 = b(1) * 10 + b(2) ==> s2为n1个位与十位对调后的数
k = 9 ==> 从9开始循环尝试找出与s2匹配的数字
Do
Call sub1(b, k) ==> b为包含k的个位与十位的数组
s1 = b(1) * 10 + b(2) ==> s1为k的个位与十位对调后的数字
If n1 + k = s2 + s1 Then ==> 如果 n1 + k = s2 + s1 则说明找到匹配对(参考上面k,s2,s1的值的说明)
Picture1.Print n1; "+"; k; "="; s1; "+"; s2 ==> 输出匹配对
End If
k = k + 1 ==> 如果当前的k值不匹配,则加1继续尝试
Loop Until k = 100 ==> 直到k=100
End Sub
Public Sub sub1(d() As Integer, k As Integer)
ReDim d(2)
d(1) = k Mod 10 ==> 得到k的个位数
d(2) = k \ 10 ==> 得到k的10的倍数,当k<100时即为k的十位数
End Sub
Private Sub Command1_Click()
Dim n1 As Integer, b() As Integer, k As Integer
Randomize ==> 产生随机系列
Picture1.Cls
n1 = Int((Rnd * 90) + 10) ==> 得到一个10到99的随机数赋给n1
Call sub1(b, n1) ==> 得到数组b,第一个元素是n1的个位,第二个元素是n1的十位
s2 = b(1) * 10 + b(2) ==> s2为n1个位与十位对调后的数
k = 9 ==> 从9开始循环尝试找出与s2匹配的数字
Do
Call sub1(b, k) ==> b为包含k的个位与十位的数组
s1 = b(1) * 10 + b(2) ==> s1为k的个位与十位对调后的数字
If n1 + k = s2 + s1 Then ==> 如果 n1 + k = s2 + s1 则说明找到匹配对(参考上面k,s2,s1的值的说明)
Picture1.Print n1; "+"; k; "="; s1; "+"; s2 ==> 输出匹配对
End If
k = k + 1 ==> 如果当前的k值不匹配,则加1继续尝试
Loop Until k = 100 ==> 直到k=100
End Sub
Public Sub sub1(d() As Integer, k As Integer)
ReDim d(2)
d(1) = k Mod 10 ==> 得到k的个位数
d(2) = k \ 10 ==> 得到k的10的倍数,当k<100时即为k的十位数
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询