#include <unistd.h>

void base_conv(int nbr, int base)
{
    if (nbr == 0) 
    {
        return; // base case: 0 in any base is just "0"
    }

    base_conv(nbr / base, base); // recursive call for the quotient

    int n = nbr % base; // calculate the remainder
    char c;
    
    if (n > 9) 
    {
        c = 'A' + n - 10; // convert digit to uppercase letter (A-F) for bases > 10
    } else {
        c = '0' + n; // convert digit to character (0-9)
    }
    write(1, &c, 1); // write the character to stdout
}

int main() 
{
    base_conv(42, 8);
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: