Prime Number Program in VB.Net

In this article, we will see Prime Number Program in VB.Net.

Prime Number Program in VB.Net
A prime number is a number that is divisible only by 1 and itself.
For example :
5 is a prime number as it is divisible by 1 and 5.
6 is not a prime number as it is divisible by 1,2,3 and 6.

Program :Prime Number Program in VB.Net

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks

Namespace ConsoleApp1
    Class Program
        Private Shared Sub Main(ByVal args As String())
            Dim number As Integer
            Dim count As Integer = 0
            Console.Write("Check whether a number is Prime or not :" & vbLf)
            Console.Write(vbLf & vbLf)
            Console.Write("Enter an number : ")
            number = Convert.ToInt32(Console.ReadLine())

            For i As Integer = 1 To number

                If number Mod i = 0 Then
                    count += 1
                End If

            If count = 2 Then
                Console.WriteLine("{0} is a Prime Number." & vbLf, number)
                Console.WriteLine("{0} is not a Prime Number." & vbLf, number)
            End If

        End Sub
    End Class
End Namespace

Result :


1 thought on “Prime Number Program in VB.Net

Leave a Reply

Your email address will not be published. Required fields are marked *