Welcome to collectivesolver - Programming & Software Q&A with code examples. A website you can trust. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il


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

Teach Your Child To Read

Dental Dog Chews
FRESH BREATHIES

GlucoTrust is a brand new, science-backed supplement that supports healthy blood sugar levels AND weight loss for men and women

Everything you need to sell anywhere

Managed VPS Hosting
Affordable. Secure. Your Own Virtual Private Hosting. Faster than AWS and Rackspace

Bonsai Boy of New York Bonsai Trees and Accessories
100%

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

25,584 questions

33,347 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
'

 




answered Sep 19 by avibootz
...