题型:综合题 题类:常考题 难易度:普通
浙江省高中信息技术 数论练习
实现上述功能的VB代码如下,请完善代码:
Private Sub Command1_Click()
Dim n As Integer, i As Integer, t As Integer,sum As Long,s As String
n=Val(Text1.Text)
For i = 1 To n^3 Step 2 ‘变量i表示连续奇数的首个整数
sum=0:t = i:flag = False
Do While sum <= n^3 And flag = False
sum =
t = t +2
IfThen flag = True
Loop
If flag = True Then Exit For
Next i
s = Str(n) + “^”+ Str(3) + “=”
Do While sum >0
If sum = 0 Then
s = s + Str(i)
Else
s = s + Str(i) +“+”
End If
i = i + 2
Loop
Text2.Text = s
End Sub
长度小于等于 100),在列表框 List1 里输出所有配对括号在表达式中的位置。例如在文本框 Text1 里入:“12*(3-(1+2))*3”,程序运行效果如图所示。
实现上述功能的 VB 代码如下,在划线的地方填入合适代码,完善程序。Private Sub Command1_Click()
Dim s As String
Dim a(1 To 100) As Integer
|
i = 1 top = 0
Do While i <= Len(s)
If Mid(s, i, 1) = "(" Then
top = top + 1
{#blank#}1{#/blank#}
End If
If Mid(s, i, 1) = ")" Then
List1.AddItem Str(a(top)) + " " + Str(i)
{#blank#}2{#/blank#}
End If
i=i+1 Loop
End Sub
试题篮