vb 改错题
改错题【题目】字符串“642138579”首尾相联形成一个数字环,依次顺序在数字环中截取2位数、3位数、4位数,使所截取得前两个数相乘等于第三个数。例如42*138=57...
改错题
【题目】字符串“642138579”首尾相联形成一个数字环,依次顺序在数字环中截取2位数、3位数、4位数,使所截取得前两个数相乘等于第三个数。例如42*138=5796。
Option Explicit
Public A(9) As Integer
Private Sub Form_Click()
Const S As String = "642138579"
Dim I As Integer, N3 As Long
Dim Idx As Integer, N1 As Long, N2 As Long
For I = 1 To 9
A(I) = Val(Mid(S, I, 1))
Next I
For I = 1 To 9
Idx = I
Call Mut(Idx, 2, N1)
Call Mut(Idx, 3, N2)
Call Mut(Idx, 4, N3)
If N3 = N1 * N2 Then
Print N1; "*"; N2; "="; N3
End If
Next I
End Sub
Private Sub Mut(ByVal Idx As Integer, N As Integer, M As Long)
Dim I As Integer
For I = 1 To N
M = M * 10 + A(Idx)
Idx = Idx + 1
If Idx > 9 Then Idx = 1
M = 0
Next I
End Sub 展开
【题目】字符串“642138579”首尾相联形成一个数字环,依次顺序在数字环中截取2位数、3位数、4位数,使所截取得前两个数相乘等于第三个数。例如42*138=5796。
Option Explicit
Public A(9) As Integer
Private Sub Form_Click()
Const S As String = "642138579"
Dim I As Integer, N3 As Long
Dim Idx As Integer, N1 As Long, N2 As Long
For I = 1 To 9
A(I) = Val(Mid(S, I, 1))
Next I
For I = 1 To 9
Idx = I
Call Mut(Idx, 2, N1)
Call Mut(Idx, 3, N2)
Call Mut(Idx, 4, N3)
If N3 = N1 * N2 Then
Print N1; "*"; N2; "="; N3
End If
Next I
End Sub
Private Sub Mut(ByVal Idx As Integer, N As Integer, M As Long)
Dim I As Integer
For I = 1 To N
M = M * 10 + A(Idx)
Idx = Idx + 1
If Idx > 9 Then Idx = 1
M = 0
Next I
End Sub 展开
展开全部
Option Explicit
'Public A(9) As Integer 换下句
Dim A(9) As Integer
Private Sub Form_Click()
Const S As String = "642138579"
Dim I As Integer, N3 As Long
Dim Idx As Integer, N1 As Long, N2 As Long
For I = 1 To 9
A(I) = Val(Mid(S, I, 1))
Print A(I);
Next I
For I = 1 To 9
Idx = I
Print I;
Call Mut(Idx, 2, N1)
Call Mut(Idx + 2, 3, N2)
Call Mut(Idx + 5, 4, N3)
Print "n1="; N1, "n2="; N2, "n3="; N3
If N3 = N1 * N2 Then
Print N1; "*"; N2; "="; N3
End If
Next I
End Sub
Private Sub Mut(ByVal Idx As Integer, N As Integer, M As Long)
Dim I As Integer
M = 0 '增加
For I = 1 To N
If Idx > 9 Then Idx = Idx Mod 9 '新增
M = M * 10 + A(Idx)
Idx = Idx + 1
'If Idx > 9 Then Idx = 1 去掉
'M = 0 去掉
Next I
End Sub
'已经运行过,只有一组能成立:42*138=5796。
'Public A(9) As Integer 换下句
Dim A(9) As Integer
Private Sub Form_Click()
Const S As String = "642138579"
Dim I As Integer, N3 As Long
Dim Idx As Integer, N1 As Long, N2 As Long
For I = 1 To 9
A(I) = Val(Mid(S, I, 1))
Print A(I);
Next I
For I = 1 To 9
Idx = I
Print I;
Call Mut(Idx, 2, N1)
Call Mut(Idx + 2, 3, N2)
Call Mut(Idx + 5, 4, N3)
Print "n1="; N1, "n2="; N2, "n3="; N3
If N3 = N1 * N2 Then
Print N1; "*"; N2; "="; N3
End If
Next I
End Sub
Private Sub Mut(ByVal Idx As Integer, N As Integer, M As Long)
Dim I As Integer
M = 0 '增加
For I = 1 To N
If Idx > 9 Then Idx = Idx Mod 9 '新增
M = M * 10 + A(Idx)
Idx = Idx + 1
'If Idx > 9 Then Idx = 1 去掉
'M = 0 去掉
Next I
End Sub
'已经运行过,只有一组能成立:42*138=5796。
展开全部
Option Explicit
Dim A(9) As Integer
Private Sub Form_Click()
Const S As String = "642138579"
Dim I As Integer, N3 As Long
Dim Idx As Integer, N1 As Long, N2 As Long
For I = 1 To 9
A(I) = Val(Mid(S, I, 1))
Next I
For I = 1 To 9
Idx = I
Call Mut(Idx, 2, N1)
Call Mut(Idx, 3, N2)
Call Mut(Idx, 4, N3)
If N3 = N1 * N2 Then
Print N1; "*"; N2; "="; N3
End If
Next I
End Sub
Private Sub Mut(Idx As Integer, N As Integer, M As Long)
Dim I As Integer
M = 0
For I = 1 To N
M = M * 10 + A(Idx)
Idx = Idx + 1
If Idx > 9 Then Idx = 1
Next I
End Sub
Dim A(9) As Integer
Private Sub Form_Click()
Const S As String = "642138579"
Dim I As Integer, N3 As Long
Dim Idx As Integer, N1 As Long, N2 As Long
For I = 1 To 9
A(I) = Val(Mid(S, I, 1))
Next I
For I = 1 To 9
Idx = I
Call Mut(Idx, 2, N1)
Call Mut(Idx, 3, N2)
Call Mut(Idx, 4, N3)
If N3 = N1 * N2 Then
Print N1; "*"; N2; "="; N3
End If
Next I
End Sub
Private Sub Mut(Idx As Integer, N As Integer, M As Long)
Dim I As Integer
M = 0
For I = 1 To N
M = M * 10 + A(Idx)
Idx = Idx + 1
If Idx > 9 Then Idx = 1
Next I
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我会VF
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询