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

51,810 answers

573 users

How to find N unique integers sum up to zero in VB.NET

1 Answer

0 votes
Imports System
Imports System.Collections.Generic

Public Class Program
    Public Shared Function UniqueIntegersSumUpToZero(ByVal n As Integer) As List(Of Integer)
        Dim result As List(Of Integer) = New List(Of Integer)(n)

        For i As Integer = 0 To n - 1
            result.Add(2 * i - n + 1)
        Next

        Return result
    End Function

    Public Shared Sub Main(ByVal args As String())
        Dim n As Integer = 7
        Dim result As List(Of Integer) = UniqueIntegersSumUpToZero(n)

        For Each val As Integer In result
            Console.Write(val & " ")
        Next
    End Sub
End Class



' run:
'
' -6 -4 -2 0 2 4 6 
'

 



answered Dec 15, 2024 by avibootz

Related questions

1 answer 77 views
2 answers 99 views
2 answers 143 views
2 answers 120 views
2 answers 118 views
...