内容发布更新时间 : 2024/11/20 8:41:42星期一 下面是文章的全部内容请认真阅读。
第四章编程题 1.查询分数题
Private Sub Form_Load()
x = Val(InputBox(\请输入分数\输入\Select Case x Case Is < 0
Label1.Caption = \输入有误\Case Is > 100
Label1.Caption = \输入有误\Case Is >= 90
Label1.Caption = \优秀\Case Is >= 80
Label1.Caption = \良好\Case Is >= 70
Label1.Caption = \一般\Case Is >= 60
Label1.Caption = \及格\Case Is < 60
Label1.Caption = \不及格\End Select End Sub
2.求最大公约数题
Private Sub Command1_Click()
Dim m As Integer, n As Integer, p As Integer m = Val(Text1.Text) n = Val(Text2.Text) If m < 0 Or n < 0 Then MsgBox \数据错误!\ End End If
p = m Mod n Do While p <> o m = n n = p
p = m Mod n Loop
Text3.Text = n End Sub
2.1最小公倍数
Private Sub Command1_Click()
Dim m As Integer, n As Integer, p As Integer, t As Integer m = Val(Text1.Text) n = Val(Text2.Text) t = m * n
If m < 0 Or n < 0 Then MsgBox \数据错误!\End End If
If m = 0 Or n = 0 Then Text3.Text = 0 Else Do
p = m Mod n If p = 0 Then Exit Do End If m = n n = p
Loop Until False Text3.Text = t / n End If End Sub
3.九九乘法表
Private Sub Command1_Click()
Dim I As Integer, J As Integer, M As Integer, s As String For I = 1 To 9 s = \
For J = 1 To I M = I * J
s = s & J & \ \ Next J
List1.AddItem s Next I End Sub
4.求ABCD—CDC=ABC题
Private Sub Command1_Click()
For a = 1 To 9: For b = 0 To 9 For c = 1 To 9: For d = 0 To 9
x = a * 1000 + b * 100 + 10 * c + d y = c * 100 + d * 10 + c z = a * 100 + b * 10 + c If x - y = z Then Print x; y; z End If Next Next Next Next End Sub
5.求前100项和,平均数题
Private Sub Form_click() n = 1: s = 0
Do While n <= 100 s = s + n n = n + 1 Loop
Print s, n - 1, s / (n - 1), s * (n - 1) End Sub
6.输入10个数找出正数,负数,零的个数
Private Sub Command1_Click() Dim i, t, x1, x2, x3 As Integer For i = 1 To 10
t = Val(InputBox(\请输入第\个数:\显示\ If t > 0 Then x1 = x1 + 1 ElseIf t < 0 Then x2 = x2 + 1 Else
x3 = x3 + 1 End If Next
Print \正数的个数:\ Print \负数的个数:\ Print \零的个数:\End Sub
7.Fibonacci数列(用数组做)
Private Sub Form_Load() For i = 1 To 30
List1.AddItem Fib(i) Next End Sub
Private Function Fib(n) If n < 3 Then Fib = 1 Else
Fib = Fib(n - 1) + Fib(n - 2) End If
End Function
Private Sub List1_Click() List1.AddItem = Fib End Sub
8.输入十个数打印并找出最大数,最小数
Private Sub Command1_Click()
Dim a(9), i, max, min As Integer For i = 0 To 9
a(i) = Val(InputBox(\请输入第\个数:\ Print a(i); Next
max = a(0) For i = 0 To 9
If a(i) > max Then max = a(i) If a(i) < min Then min = a(i) Next Print Print Print
Print \最大数为:\最小数为:\End Sub
9.100元换成40张等值的10,5,2,1的钱的题
Private Sub Command1_Click() For x = 1 To 10 For y = 1 To 20