How to find the Kth smallestt number in an unsorted array with VB.NET

1 Answer

0 votes
Imports System

Module KthSmallestFinder

    Function FindKthSmallestNumber(arr As Integer(), k As Integer) As Integer
        Array.Sort(arr)
		
        Return arr(k - 1)
    End Function

    Sub Main()
        Dim arr As Integer() = {42, 90, 21, 30, 37, 81, 45}
        Dim k As Integer = 3

        Dim result As Integer = FindKthSmallestNumber(arr, k)
		
        Console.WriteLine(result) 
    End Sub

End Module


				
' run:
'
' 37
'

 



answered Nov 11 by avibootz
...