Last active
April 29, 2022 20:36
-
-
Save CodeMaster7000/0aa49cb8e7d8d2406abfae93b035bdfe to your computer and use it in GitHub Desktop.
A simple program coded in PHP which prints the Collatz sequence for the inputted number.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function printCollatz($n) | |
{ | |
while ($n != 1) | |
{ | |
echo $n . " "; | |
if ($n & 1) | |
$n = 3 * $n + 1; | |
else | |
$n = $n / 2; | |
} | |
echo $n; | |
} | |
//Enter the number you wish to input here. | |
printCollatz(40); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment