Skip to content

Instantly share code, notes, and snippets.

@b4284
Created November 22, 2016 16:35
Show Gist options
  • Select an option

  • Save b4284/dda740bbaf8f9274fe43895c12b3c547 to your computer and use it in GitHub Desktop.

Select an option

Save b4284/dda740bbaf8f9274fe43895c12b3c547 to your computer and use it in GitHub Desktop.
ptt freshman mid-exam question 2
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