Skip to content

Instantly share code, notes, and snippets.

@byelims
Created August 14, 2013 06:56
Show Gist options
  • Save byelims/6228608 to your computer and use it in GitHub Desktop.
Save byelims/6228608 to your computer and use it in GitHub Desktop.
From USACO Section 1.2 Palindromic Squares
/* put the base b representation of n into s: 0 is represented by "" */
void
numbconv(char *s, int n, int b)
{
int len;
if (n == 0) {
strcpy(s, "");
return;
}
/* figure out first n-1 digits */
numbconv(s, n/b, b);
/* add last digit */
len = strlen(s);
s[len] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[n%b];
s[len+1] = '\0';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment