VB.net Program to Find the First Repeated Element in the One-Dimensional Array

You are currently viewing VB.net Program to Find the First Repeated Element in the One-Dimensional Array

VB.Net program to find the first repeated element in the one-dimensional array

'VB.Net program to find the first repeated element 
'in a one-dimensional array.

Module Module1

    Sub Main()
        Dim arr As Integer() = New Integer(6) {}
        Dim index As Integer = 0
        Dim item As Integer = 0

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

        index = -1
        'check first repeated element


        For i = 0 To 5 Step 1
            For j = i + 1 To 5 Step 1
                If (arr(i) = arr(j)) Then
                    item = arr(j)
                    index = j
                    GoTo OUT
                End If
            Next
        Next
OUT:

        If (index <> -1) Then
            Console.WriteLine("{0} repeated @ {1} index", item, index)
        Else
            Console.WriteLine("There is no repeated element")
        End If
    End Sub

End Module
Enter array elements:
Element[0]: 10
Element[1]: 12
Element[2]: 12
Element[3]: 14
Element[4]: 15
Element[5]: 16
12 repeated @ 2 index
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