VB 改错题【题目】将随机生成的5个正整数的各位数字进行逆序,并分别求这5个数的各位数字之和。
OptionExplicitOptionBase1PrivateSubForm_Click()Dimx(5)AsInteger,sum(5)AsInteger,iAsIn...
Option Explicit
Option Base 1
Private Sub Form_Click()
Dim x(5) As Integer, sum(5) As Integer, i As Integer
Randomize
For i = 1 To 5
x(i) = Int(Rnd * 9000 + 1000)
List1.AddItem x(i)
Next i
Print
Call rever(x, sum)
For i = 1 To 5
List2.AddItem "逆序后的值为:", x(i), "; 数字和 = ", sum(i)
Next i
End Sub
Private Sub rever(x() As Integer, s() As Integer)
Dim j As Integer, a As Integer, k As Integer
For j = 1 To UBound(x)
Do
a = x(j) Mod 10
k = k * 10 + a
s(j) = s(j) + k
x(j) = x(j) \ 10
k = 0
Loop Until x(j) = 0
x(j) = k
Next j
End Sub 展开
Option Base 1
Private Sub Form_Click()
Dim x(5) As Integer, sum(5) As Integer, i As Integer
Randomize
For i = 1 To 5
x(i) = Int(Rnd * 9000 + 1000)
List1.AddItem x(i)
Next i
Call rever(x, sum)
For i = 1 To 5
List2.AddItem "逆序后的值为:", x(i), "; 数字和 = ", sum(i)
Next i
End Sub
Private Sub rever(x() As Integer, s() As Integer)
Dim j As Integer, a As Integer, k As Integer
For j = 1 To UBound(x)
Do
a = x(j) Mod 10
k = k * 10 + a
s(j) = s(j) + k
x(j) = x(j) \ 10
k = 0
Loop Until x(j) = 0
x(j) = k
Next j
End Sub 展开
1个回答
展开全部
Option Explicit
Option Base 1
Private Sub Form_Click()
Dim x(5) As Integer, sum(5) As Integer, i As Integer
Randomize
For i = 1 To 5
x(i) = Int(Rnd * 9000 + 1000)
List1.AddItem x(i)
Next i
Call rever(x, sum)
For i = 1 To 5
List2.AddItem "逆序后的值为:", x(i), "; 数字和 = ", sum(i)
Next i
End Sub
Private Sub rever(x() As Integer, s() As Integer)
Dim j As Integer, a As Integer, k As Integer
For j = 1 To UBound(x)
Do
a = x(j) Mod 10
k = k * 10 + a
x(j) = x(j) \ 10
Loop Until x(j) = 0
s(j) = s(j) + k
x(j) = k
k = 0
Next j
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询