Skip to main content

How to Get Prime Numbers in VB.Net

Screenshot
Body
Now, let’s create a simple program which is how to get prime numbers in VB.Net. You will learn here how to easily determine the prime numbers between 1 to 100. This simple program is also powerful that you can use to test large numbers to see if they are “prime”. Just follow the steps below.

Creating Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application. Then, add a Button and a Label in the Form just like shown below. prime21

Step 2

Double click the Button to fire the click event handler of it and do the following codes for getting the prime numbers from 1 to 100.
  1. Dim prime, numbers, i As Integer
  2. prime = 1
  3. MsgBox(“The prime Numbers are : ”)
  4. For numbers = 1 To 100
  5. For i = 2 To numbers - 1
  6. If numbers Mod i = 0 Then
  7. prime = 0
  8. Exit For
  9. Else
  10. prime = 1
  11. End If
  12.  
  13. Next
  14. If prime = 1 Then
  15. MsgBox(numbers)
  16. End If
  17. Next
For any questions about this article. You can contact me @ Email – [email protected] Mobile No. – 09305235027 – TNT FB Account – https://www.facebook.com/onnaj.soicalap

Add new comment