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,907 questions

51,839 answers

573 users

How to splits an array of integers into two arrays with VB.NET

2 Answers

0 votes
Module Module1

    Sub Main()

        Dim arr(9) As Integer

        Randomize()
        For i As Integer = 0 To arr.Length - 1
            arr(i) = Int(Rnd() * 100) + 1
        Next
        For Each number In arr
            Console.WriteLine(number)
        Next

        Dim divisor = 2
        Dim remainder As Integer
        Dim boundary = Math.DivRem(arr.GetLength(0), divisor, remainder)

        Dim arr1(boundary - 1 + remainder), arr2(boundary - 1) As Integer
        Array.Copy(arr, 0, arr1, 0, boundary + remainder)
        Array.Copy(arr, boundary + remainder, arr2, 0, arr.Length - boundary)

        Console.WriteLine()
        For Each number In arr1
            Console.WriteLine(number)
        Next
        Console.WriteLine()
        For Each number In arr2
            Console.WriteLine(Number)
        Next

    End Sub

End Module

' run:
' 
' 77
' 72
' 1
' 10
' 60
' 75
' 59
' 65
' 37
' 40

' 77
' 72
' 1
' 10
' 60

' 75
' 59
' 65
' 37
' 40

 



answered Aug 13, 2018 by avibootz
0 votes
Module Module1

    Sub Main()

        Dim arr(9) As Integer

        Randomize()
        For i As Integer = 0 To arr.Length - 1
            arr(i) = Int(Rnd() * 100) + 1
        Next
        For Each number In arr
            Console.WriteLine(number)
        Next

        Dim boundary As Integer = arr.Length / 2 - 1

        Dim arr1(boundary), arr2(boundary) As Integer
        Array.Copy(arr, 0, arr1, 0, boundary + 1)
        Array.Copy(arr, boundary + 1, arr2, 0, boundary + 1)

        Console.WriteLine()
        For Each number In arr1
            Console.WriteLine(number)
        Next
        Console.WriteLine()
        For Each number In arr2
            Console.WriteLine(number)
        Next

    End Sub

End Module

' run:
' 
' 6
' 73
' 25
' 55
' 80
' 54
' 99
' 11
' 2
' 35

' 6
' 73
' 25
' 55
' 80

' 54
' 99
' 11
' 2
' 35

 



answered Aug 13, 2018 by avibootz
...