vb.net

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("---------------------------------------")
            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
            Next

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

            Console.ReadKey()
        End Sub
    End Class
End Namespace

Result :
prime-number-program-vb-net

prime-number-program-vb-net

Leave a Reply

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