题型:综合题 题类:常考题 难易度:普通
高中信息技术综合库——枚举算法3
问题:实现上述功能的VB 代码如下,但加框处代码有错,请改正。
Private Sub Command1_Click()
Dim n as long , sum as long , i As Long Dim x as long , y as long
List1.Clear
n = Val(Text1.Text) sum = 0
For i = 10 To n
x = ‘①
y = 0
Do While x > 0
y = ‘②
x = x \ 10
Loop
If y = i Then
List1.additem Str(i)
sum = sum+1
End if
Next i
Label1.caption = “共有”& Str(sum) & “个回文数” End Sub
①②
Dim sum As Integer 'sum 用来统计符合条件的自然数个数'
Dim n, max As Integer
List1.Clear
sum = 0
max = {#blank#}1{#/blank#}'指定查找范围的最大自然数,Text1文本框中输入'
n = 0
Do While n <= max
n = n + 1 '从自然数1开始不断往上寻找'
If {#blank#}2{#/blank#}Then
List1.AddItem Str(n) '找到后在List1中显示结果'
{#blank#}3{#/blank#}
End If
Loop
List1.AddItem ("共计" + Str(sum) + "个")
End Sub
试题篮