vb第四章选择结构和循环结构编程题.docVIP

  • 9
  • 0
  • 约8.47千字
  • 约 11页
  • 2017-05-12 发布于河南
  • 举报
vb第四章选择结构和循环结构编程题

第四章编程题 1.查询分数题 Private Sub Form_Load() x = Val(InputBox(请输入分数, 输入, 0)) 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 九九乘法表 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 * I = M 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 求前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(请输入第 i 个数:, 显示, 0)) If t 0 Then x1 = x1 + 1 ElseIf t 0 Then x2 = x2 + 1 Else x3 = x3 + 1 End If Next Print 正数的个数: x1 Print 负数的个数: x2 Print 零的个数: x3

文档评论(0)

1亿VIP精品文档

相关文档