What is a prime number and how to write a visual basic program to find prime numbers? Another example of a Vb program to find prime numbers between 1 to 100.
Before starting the writing program will understand what is a prime number? Then will write the code to find prime number in Visual basic. Check more visual basic programs with examples.
What is a prime number
A number that is divisible only by itself and 1. Example: (2, 3, 5, 7, 11, 13, 17). One is not a prime number according to the definition a Prime number is divisible with 1 and itself and one doesn’t have exactly two positive divisors.
Visual Basic program to find the prime numbers between 1 to 100
This is an example of a VB program to print the prime numbers between 1 to 100.
Private Sub cmdPrime_Click() Dim p, n, i As Integer p = 1 Print “Prime Numbers are : “ For n = 1 To 100 For i = 2 To n – 1 If n Mod i = 0 Then p = 0 Exit For Else p = 1 End If Next If p = 1 Then Print n End If Next End Sub