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

51,769 answers

573 users

How to convert an array of digits to an integer add 1 and convert it back to an array of digits in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Public Shared Function ConvertArrayOfDigitsToIntNumber(ByVal arr As Integer()) As Integer
        Dim n As Integer = 0

        For Each digit As Integer In arr
            n = n * 10 + digit
        Next

        Return n
    End Function

    Public Shared Sub ConvertIntNumberToArrayOfDigits(ByVal digits As Integer(), ByVal n As Integer)
        Dim i As Integer = digits.Length - 1

        While n > 0
            digits(i) = n Mod 10
            n = n \ 10
            i -= 1
        End While
    End Sub

    Public Shared Sub Main(ByVal args As String())
        Dim arr As Integer() = {9, 4, 6, 9}
	
        Dim n As Integer = ConvertArrayOfDigitsToIntNumber(arr)
	
        n += 1
	
        ConvertIntNumberToArrayOfDigits(arr, n)
	
        Console.WriteLine("n = " & n)
        Console.WriteLine(String.Join(", ", arr))
    End Sub
End Class



' run:
'
' n = 9470
' 9, 4, 7, 0
'

 



answered May 6, 2024 by avibootz
...