1、选择排序
创新互联公司长期为上1000+客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为善左企业提供专业的网站设计制作、成都网站设计,善左网站改版等技术服务。拥有10多年丰富建站经验和众多成功案例,为您定制开发。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
不断更新中,敬请期待。
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。