您好,登录后才能下订单哦!
1、选择排序
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
不断更新中,敬请期待。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。