Skip to content

Instantly share code, notes, and snippets.

@kenornotes
Created January 16, 2015 08:46
Show Gist options
  • Save kenornotes/9381b17845f68a532c90 to your computer and use it in GitHub Desktop.
Save kenornotes/9381b17845f68a532c90 to your computer and use it in GitHub Desktop.
#include <stdio.h>
void print(int val, int base) {
int i;
char output[100];
for(i = 0 ;val != 0; i++, val /= base)
val%base < 9?(output[i]=(char)(val%base+'0')):(output[i]=(char)(val%base+'A'-10));
for(;i >= 0 ;i--)
printf("%c",output[i]);
printf("\n");
}
int main() {
int num, base;
scanf("%d %d", &num, &base);
print(num, base);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment