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

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

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

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to implement the collatz sequence in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
	Public Shared Sub collatz_sequence(ByVal n As Integer)
        Console.Write(n & " ")

        While n > 1
            If n Mod 2 = 0 Then
                n = n / 2
            Else
                n = 3 * n + 1
            End If

            Console.Write(n & " ")
        End While
    End Sub

	Public Shared Sub Main()
        collatz_sequence(7)
    End Sub
End Class




' run:
'
' 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
'

 





answered Jul 28, 2022 by avibootz

Related questions

1 answer 29 views
1 answer 39 views
1 answer 49 views
1 answer 41 views
...