Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void to_base(unsigned long n, int base);
- int main(void){
- unsigned long number;
- int base=2;
- printf("Enter an integer (q to quit):\n");
- while(scanf("%lu", &number)==1 && (base>=2 && base<=10)){
- printf("Enter a base to convert to (2-10):");
- scanf("%d", &base);
- printf("Binary equivalent: ");
- to_base(number, base);
- putchar('\n');
- printf("Enter an integer (q to quit):\n");
- }
- printf("Done.\n");
- return 0;
- }
- void to_base(unsigned long n, int base){
- int r;
- r=n%base;
- if (n>=base)
- to_base(n/base, base);
- putchar('0'+r);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement