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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,870 questions

51,793 answers

573 users

How to check if array contains all elements of a given range in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Public Shared Function check_elements(ByVal arr As Integer(), ByVal rang_from As Integer, ByVal rang_to As Integer) As Boolean
        Dim range As Integer = rang_to - rang_from
        Dim size As Integer = arr.Length

        For i As Integer = 0 To size - 1
            If arr(i) >= rang_from AndAlso arr(i) <= rang_to Then
                Dim j As Integer = arr(i) - rang_from

                If arr(j) > 0 Then
                    arr(j) = arr(j) * -1
                End If

                For k As Integer = 0 To size - 1
                    Console.Write(arr(k) & " ")
                Next

                Console.WriteLine()
            End If
        Next

        For i As Integer = 0 To range - 1
            If arr(i) > 0 Then Return False
        Next

        Return True
    End Function

    Public Shared Sub Main()
        Dim arr As Integer() = {1, 4, 5, 2, 3, 7, 8, 3, 9, 4, 4, 0, 6}
        Dim rang_from As Integer = 3, rang_to As Integer = 7

        If check_elements(arr, rang_from, rang_to) Then
            Console.Write("Yes")
        Else
            Console.Write("No")
        End If
    End Sub
End Class


	
	
	
' run:
'
' 1 -4 5 2 3 7 8 3 9 4 4 0 6 
' 1 -4 -5 2 3 7 8 3 9 4 4 0 6 
' -1 -4 -5 2 3 7 8 3 9 4 4 0 6 
' -1 -4 -5 2 -3 7 8 3 9 4 4 0 6 
' -1 -4 -5 2 -3 7 8 3 9 4 4 0 6 
' -1 -4 -5 2 -3 7 8 3 9 4 4 0 6 
' -1 -4 -5 2 -3 7 8 3 9 4 4 0 6 
' -1 -4 -5 -2 -3 7 8 3 9 4 4 0 6 
' Yes
'

 



answered Dec 14, 2021 by avibootz

Related questions

...