Pages

Search This Blog

Check whether an element is existing or not inside an array and find the position of it


Module SearchAndMultiPosition

    Sub Main()
        Dim n, i, c, t As Integer
        Console.Write("Enter the number of Elements: ")
        n = CInt(Console.ReadLine())
        Dim arr(n) As Integer
        For i = 0 To n - 1
            Console.Write("arr(" & (i).ToString & ") : ")
            arr(i) = CInt(Console.ReadLine())
        Next
        Console.WriteLine("Array Contains...")
        For i = 0 To n - 1
            Console.Write(arr(i) & " ")
        Next
        Console.WriteLine()
        Console.Write("Enter an Number to Check: ")
        t = CInt(Console.ReadLine())
        c = 0
        For i = 0 To n - 1
            If t = arr(i) Then
                c = 1
                Console.WriteLine(t.ToString() + " is present in arr(" & i & ")")
            End If
        Next
        If c = 0 Then
            Console.WriteLine(t.ToString() + " is NOT present in the list")
        End If
        Console.ReadLine()
    End Sub
End Module

No comments:

Post a Comment