VB.net Program to Find the Prime Numbers From the Array of Integers

You are currently viewing VB.net Program to Find the Prime Numbers From the Array of Integers

VB.Net program to find the prime numbers from the array of integers

'VB.Net program to find the prime numbers 
'from the array of integers.

Module Module1

    Sub Main()
        Dim arr As Integer() = New Integer(5) {}
        Dim flag As Integer = 0
        Dim i, j As Integer = 0

        Console.WriteLine("Enter array elements: ")
        For i = 0 To 4 Step 1
            Console.Write("Element[{0}]: ", i)
            arr(i) = Integer.Parse(Console.ReadLine())
        Next

        Console.WriteLine("Prime Numbers are: ")
        For i = 0 To 4 Step 1

            flag = 0
            For j = 2 To (arr(i) / 2) Step 1
                If arr(i) Mod j = 0 Then
                    flag = 1
                End If
            Next
            If flag = 0 Then
                Console.Write("{0} ", arr(i))
            End If
        Next
        Console.WriteLine()
    End Sub
    
End Module
Enter array elements:
Element[0]: 2
Element[1]: 3
Element[2]: 4
Element[3]: 5
Element[4]: 6
Prime Numbers are:
2 3 5
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply