当前位置:   article > 正文

VB学习第十周素数判断,随机数产生

VB学习第十周素数判断,随机数产生
  1.  Public Class Form1
  2. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
  3. If Asc(e.KeyChar) = 13 Then
  4. Dim i, m As Integer, Tag As Boolean
  5. m = Val(TextBox1.Text)
  6. Tag = True
  7. i = 2
  8. Do
  9. If (m Mod i) = 0 Then
  10. Tag = False
  11. Label2.Text = m & "不是素数"
  12. Exit Do
  13. End If
  14. i = i + 1
  15. Loop While (2 <= i And i <= m - 1)
  16. If i = m Then Label2.Text = m & "是素数"
  17. End If
  18. End Sub
  19. Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  20. End Sub
  21. End Class


随机数产生!

  1. Public Class Form1
  2. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  3. Dim i, a, s, max, min As Integer
  4. max = 1 : min = 100
  5. Label1.Text = ""
  6. For i = 1 To 10
  7. a = Int(Rnd() * 100 + 1)
  8. Label1.Text &= a & " "
  9. If a > max Then max = a
  10. If a < min Then min = a
  11. s = s + a
  12. Next
  13. Label3.Text = max & Space(15) & min & Space(15) & s / 10
  14. End Sub
  15. End Class


 

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号