Some code in vb.net

Source: Internet
Author: User

1. Select sorting

Public Class Form1
Dim a (10) As Integer
Private Sub button#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. Bubble Sorting

Public Class Form1

 

Private Sub button#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. Calculate the prime number from 1 to 100.

Public Class Form1

Private Sub button#click (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles Button1.Click
Dim n %, j %, I %
J = Val (InputBox ("input", "n value "))
For n = 1 To j
For I = 2 To Math. Sqrt (n)
If (n Mod I = 0) Then
Exit
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

 

Updates are coming soon.

 

This article is from the "cloud computing" blog. For more information, contact the author!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.