Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing

What's The REAL Secret To First Date Success With a Woman? Click Here To Find Out

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

29,372 questions

38,322 answers

573 users

How to find two numbers from an array that are just smaller and just greater than N in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Public Shared Sub Main()
        Dim arr As Integer() = New Integer() {3, 8, 1, 9, 4, 10, 7, 13, 2, 6}
        Dim size As Integer = arr.Length
        Dim N As Integer = 4
		
        Dim just_greater As Integer = Integer.MaxValue
        Dim just_smaller As Integer = Integer.MinValue

        For i As Integer = 0 To size - 1
            If arr(i) > N AndAlso arr(i) < just_greater Then
                just_greater = arr(i)
            End If

            If arr(i) < N AndAlso just_smaller < arr(i) Then
                just_smaller = arr(i)
            End If
        Next

        Console.WriteLine("just_smaller: " & just_smaller)
        Console.WriteLine("N: " & N)
        Console.WriteLine("just_greater: " & just_greater)
    End Sub
End Class




' run:
'
' just_smaller: 3
' N: 4
' just_greater: 6
'

 


Protect Your Privacy - Download VPN


answered Sep 19, 2022 by avibootz
...