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
展开
 我来答
Yuqi_Tan

2008-06-24 · TA获得超过8.9万个赞
知道大有可为答主
回答量:9918
采纳率:93%
帮助的人:3467万
展开全部
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。
0871love
2008-06-24 · TA获得超过3518个赞
知道大有可为答主
回答量:1418
采纳率:50%
帮助的人:1613万
展开全部
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
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
biran0824
2008-06-24 · TA获得超过1.8万个赞
知道大有可为答主
回答量:3029
采纳率:0%
帮助的人:2462万
展开全部
我会VF
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式