-
-
Save b4284/dda740bbaf8f9274fe43895c12b3c547 to your computer and use it in GitHub Desktop.
ptt freshman mid-exam question 2
This file contains hidden or 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
| void q2(int n) { | |
| bool shown = false; | |
| char one_zero; | |
| int n2 = 0x80; | |
| CAL: | |
| if (n >= n2) { | |
| n -= n2; | |
| one_zero = '1'; | |
| } else { | |
| one_zero = '0'; | |
| } | |
| if (shown) { | |
| putchar('_'); | |
| putchar(one_zero); | |
| } else { | |
| if (one_zero == '1' || n2 == 1) { | |
| shown = true; | |
| putchar(one_zero); | |
| } | |
| } | |
| if (n2 > 1) { | |
| n2 /= 2; | |
| goto CAL; | |
| } else { | |
| putchar('\n'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment