vb.net中的部分代码
1、选择排序
创新互联公司自2013年创立以来,是专业互联网技术服务公司,拥有项目成都网站设计、成都网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元碌曲做网站,已为上家服务,为碌曲各地企业和个人服务,联系电话:13518219792
Public Class Form1
Dim a(10) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer, j As Integer, k As Integer, t As Integer
For i = 0 To 10
a(i) = Int(Rnd() * 100 + 1)
Next
For i = 0 To 9
k = i
For j = i + 1 To 10
If a(k) > a(j) Then
k = j
End If
t = a(k)
a(k) = a(i)
a(i) = t
Next
Next
For i = 0 To 10
Console.Write(a(i) & Space(2))
Next
End Sub
End Class
2、冒泡排序
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a(10) As Integer
Dim i As Integer, j As Integer, t As Integer, k As Integer
For i = 0 To 10
a(i) = Int(Rnd() * 100 + 1)
Next
For i = 0 To 9
For j = 1 To 10 - i
k = j - 1
If (a(k) > a(j)) Then
t = a(k)
a(k) = a(j)
a(j) = t
End If
k = k + 1
Next
Next
For i = 0 To 10
Console.Write(a(i) & Space(2))
Next
End Sub
End Class
3、求1到100内的素数
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim n%, j%, i%
j = Val(InputBox("输入", "n值"))
For n = 1 To j
For i = 2 To Math.Sqrt(n)
If (n Mod i = 0) Then
Exit For
End If
Next
If (i > Math.Sqrt(n)) Then
Label1.Text = Label1.Text & n
End If
Next
End Sub
End Class
Dim a%, b%, c%
For a = 0 To 10
For b = 0 To 10
For c = 0 To 10
If a * a + b * b + c * c = 100 Then
Label1.Text = Label1.Text & a & b & c & vbCrLf
End If
Next
Next
Next
不断更新中,敬请期待。
名称栏目:vb.net中的部分代码
网站链接:http://hbruida.cn/article/ihhoss.html