VB.net Program to Find the Second Smallest Element From the Array of Integers

You are currently viewing VB.net Program to Find the Second Smallest Element From the Array of Integers

VB.Net program to find the second smallest element from the array of integers

'VB.Net program to find the second smallest element 
'from the array of integers.

Module Module1

    Sub Main()
        Dim arr As Integer() = New Integer(5) {}
        Dim small As Integer = 0
        Dim second_small As Integer = 0
        Dim i 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

        'Find the second smallest element from array
        small = arr(0)
        For i = 1 To 4 Step 1
            If (small > arr(i)) Then
                second_small = small
                small = arr(i)
            End If
        Next
        Console.WriteLine("Second smallest element in array is: {0}", second_small)
    End Sub
    
End Module
Enter array elements:
Element[0]: 40
Element[1]: 50
Element[2]: 30
Element[3]: 20
Element[4]: 10
Second smallest element in array is: 20
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