Find a Nth highest or lowest numbers in a given series of integers using for loop Of VB.net

Rajnilari2015
Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 103
Imports System.Collections.Generic

Namespace ConsoleApplication2
Class Program
Private Shared Sub Main(args As String())
'Question #3: Find a Nth highest or lowest number in a given series of numbers.
Dim lstNumbers As New List(Of Double)() From { _
1, _
2.06, _
-36.4, _
-4, _
5.9, _
61.9, _
79.8, _
8, _
9, _
18.0, _
23.7 _
}
Dim minNum As Double = 0
Dim maxNum As Double = 0

minNum = lstNumbers(0)
maxNum = lstNumbers(0)
For i As Integer = 1 To lstNumbers.Count - 1
'logic for obtaining the Minimum Number
If minNum > lstNumbers(i) Then
minNum = lstNumbers(i)
End If

'logic for obtaining the Maximum Number
If maxNum < lstNumbers(i) Then
maxNum = lstNumbers(i)
End If
Next
Console.WriteLine("Min = {0} , Max = {1}", minNum, maxNum)
Console.ReadKey(True)
End Sub
End Class
End Namespace

Comments or Responses

Login to post response