vb题,求大神
下面程序的功能是找出123456~234567范围内的符合要求的整数。该数是一个升序数,并且这个数的前3位数、其后的2位数以及最后一位数分别组成的三个整数之和也是一个升序...
下面程序的功能是找出123456~234567范围内的符合要求的整数。该数是一个升序数,并且这个数的前3位数、其后的2位数以及最后一位数分别组成的三个整数之和也是一个升序数。例如:123469:123 + 46 + 9 = 178,123469与178均为升序数。(如果一个整数的各位数字的数值自左至右依次增加,则称该数为升序数。)
Option Explicit
Private Sub Command1_Click()
Dim i As Long, sum As Long, st As String
For i = 123456 To 234567
If Ascend(i) Then
sum = 0
(1)
Call Add(i, sum, st)
If Ascend(sum) Then
st = i & ": " & Left(st, Len(st) - 1) & "=" & sum
List1.AddItem st
End If
End If
Next i
End Sub
Private Sub Add(ByVal n As Long, sum As Long, st As String)
Dim k As Integer, T As Integer
For k = 3 To 1 Step -1
T = (2) '截取数字
st = st & T & "+"
sum = sum + T
n = Val(Mid(n, k + 1))
Next k
End Sub
Private Function Ascend( (3) ) As Boolean
Dim k As Integer, f1 As Integer, f2 As Integer, T As Integer
k = Len(CStr(n)) - 1
f1 = n \ 10 ^ k
Do
n = n Mod 10 ^ k
k = k - 1
f2 = n \ 10 ^ k
If f1 >= f2 Then Exit Function
f1 = f2
Loop Until k = 0
(4)
End Function 展开
Option Explicit
Private Sub Command1_Click()
Dim i As Long, sum As Long, st As String
For i = 123456 To 234567
If Ascend(i) Then
sum = 0
(1)
Call Add(i, sum, st)
If Ascend(sum) Then
st = i & ": " & Left(st, Len(st) - 1) & "=" & sum
List1.AddItem st
End If
End If
Next i
End Sub
Private Sub Add(ByVal n As Long, sum As Long, st As String)
Dim k As Integer, T As Integer
For k = 3 To 1 Step -1
T = (2) '截取数字
st = st & T & "+"
sum = sum + T
n = Val(Mid(n, k + 1))
Next k
End Sub
Private Function Ascend( (3) ) As Boolean
Dim k As Integer, f1 As Integer, f2 As Integer, T As Integer
k = Len(CStr(n)) - 1
f1 = n \ 10 ^ k
Do
n = n Mod 10 ^ k
k = k - 1
f2 = n \ 10 ^ k
If f1 >= f2 Then Exit Function
f1 = f2
Loop Until k = 0
(4)
End Function 展开
2个回答
展开全部
(1) st = ""
(2) Val(Left(CStr(n), k))
(3) ByVal n As Long
(4) If f1 = f2 Then Ascend = True
(2) Val(Left(CStr(n), k))
(3) ByVal n As Long
(4) If f1 = f2 Then Ascend = True
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
--
2022-12-05 广告
2022-12-05 广告
图形化编程简单理解为用积木块形式编程,scratch和python也是其中的一种,属于入门级编程,以其简单生动的画面获得无数学生的喜爱,深圳市创客火科技有限公司是一家做教育无人机的公司,旗下有编程无人机,积木无人机及室内外编队,每款飞机含有...
点击进入详情页
本回答由--提供
展开全部
Private Sub Command1_Click()
Dim d As Long, h As Long
Dim a(6) As Integer, b(3) As Integer
Dim i As Integer
For d = 123456 To 234567
'For d = 123456 To 123457
h = d
'Print h
For i = 1 To 5
a(i) = h \ (10 ^ (6 - i))
h = h - a(i) * (10 ^ (6 - i))
'Print a(i);
Next
a(6) = h Mod 10
'Print a(6)
If a(1) < a(2) And a(2) < a(3) And a(3) < a(4) And a(4) < a(5) And a(5) < a(6) Then
'Print d
b(0) = (a(1) * 100 + a(2) * 10 + a(3)) + (a(4) * 10 + a(5)) + a(6)
'Print b(0),
For i = 1 To 2
b(i) = b(0) \ (10 ^ (3 - i))
b(0) = b(0) - b(i) * (10 ^ (3 - i))
Next
b(3) = b(0) Mod 10
If b(1) < b(2) And b(2) < b(3) Then
Print d
End If
End If
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询