Last active
March 11, 2022 09:12
-
-
Save yeonwooz/f9e21cf87a25b12a313554faf57108a8 to your computer and use it in GitHub Desktop.
MakeBinary
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
public static void MakeBinaryRecursive(uint n) | |
{ | |
if (n / 2 == 1) // 3. base case | |
{ | |
Console.Write((n / 2).ToString() + (n % 2).ToString()); | |
return; | |
} | |
// 1. recursive step | |
if (n / 2 > 1) | |
{ | |
// push in stack | |
MakeBinaryRecursive(n / 2); // 2-1. input is half of current n | |
// pop out of stack | |
Console.Write((n % 2).ToString()); // 2-2. no output is needed. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment