# 高中学业水平考试——信息技术 ——程序改错

Dim Age As Integer, Tree As Integer Age = 17 Tree = 3 Do Age = Age + 1 Tree = Tree + Age - 14 Loop Until Tree >= 100 Print "到"; Age; "岁时种到 100 棵树"

Private Sub Command1_Click() Dim Age As Integer, Tree As Integer Age = 17 Do Age = Age + 1 Tree = Tree + Age - 14 Loop Until Tree = 100 Print "到"; Age; "岁时种到 100 棵树" End Sub

2、累乘（1×2×3×……×9×10=？） Private Sub Command1_Click() Dim S As Integer, A As Integer For A = 1 To 10 S = S *A Next S Print "S="; S End Sub Private Sub Command1_Click() Dim S As Integer, A As Integer S=1 For A = 1 To 10 S = S *A Next A Print "S="; S

3、求解一元二次方程的程序

Private Sub Command5_Click() Dim a, b, c, d As Integer Dim x1, x2 As Single a = InputBox("请输入二次项系数：", "输入") b = InputBox("请输入一次项系数：", "输入") c = InputBox("请输入常数项：", "输入") d=b^2-4ac If d >= 0 Then x1 = (-b + Sqr(d)) / 2 * a x2 = (-b - Sqr(d)) / 2 * a Print "X1="; x1, "X2="; x2 Else Print "此一元二次方程无解！" End Sub Dim a, b, c, d As Integer Dim x1, x2 As Single a = InputBox("请输入二次项系数：", "输入") b = InputBox("请输入一次项系数：", "输入") c = InputBox("请输入常数项：", "输入") d=b^2-4*a*c If d >= 0 Then x1 = (-b + Sqr(d)) / 2 * a x2 = (-b - Sqr(d)) / 2 * a Print "X1="; x1, "X2="; x2 Else Print "此一元二次方程无解！" End If

4、百钱买百鸡： “今有鸡翁一值钱五，鸡母一值钱三，鸡雏三值钱一，凡百钱买百鸡，问鸡翁、鸡母、鸡雏 各几何。。 ” For a = 0 To 20 Private Sub Command1_Click() For b = 0 To 33 Dim a As Integer, b As Integer, c As Integer For c = 0 To 99 Step 3 For a = 0 To 20 For b = 0 To 33 For c = 0 To 99 Step 3 If (a + b + c = 100) Or (5 * a + 3 * b + c / 3 = 100) Then Print a, b, c If (a + b + c = 100) And (5 * a + 3 * b + c / 3 = 100) Then Print a, b, c Next c Next b Next a

Next a Next b Next c End Sub

5、判断某年是否闰年 Private Sub Command1_Click() Dim N As Integer N = InputBox("输入年号：", "判断闰年", 2000) If N / 100 <> N \ 100 Then If N Mod 400 = 0 Then Print "不是闰年" Else Print "闰年" If N / 100 = N \ 100 Then Else If N Mod 4 = 0 Then Print "不是闰年" Else Print "闰年" End If End Sub If N Mod 400 = 0 Then Print "闰年" Else Print "不是闰年" Else If N Mod 4 = 0 Then Print "闰年" Else Print "不是闰年" End If Dim N As Integer N = InputBox("输入年号：", "判断闰年", 2000)