#include <stdio.h>
void to_base_n(unsigned long *n, int *b);

int main(void){
    unsigned long num;
    int bin;
    printf("Enter: num base(2-10)\t(q to quit):\n");
    printf("Enter: ");
    while (scanf(" %ld %d", &num, &bin) == 2){
        if(bin>1&&bin<11){
        to_base_n(&num,&bin);
        putchar('\n');
        printf("Enter: ");
        }else(printf("base is out of range\nEnter: "));
    }
    return 0;
}

void to_base_n(unsigned long *n, int *b){
    int r;
    r = *n % *b;
    if (*n >= *b){
        *n = *n / *b;
        to_base_n(n,b);
    }
    putchar('0' + (r % *b));
    return;
}
