Search code examples
cfunctionoctal

C function to convert from decimal to octal


I am working on a homework problem that asks us to write a function in C that will convert from decimal to octal. Here's what I have so far

int oct(int num) {
    if (num < 8) {
        return num;
    }
    else {

    }
}

So yeah I'm pretty stuck, any help is very much appreciated Thanks


Solution

  • You can use %o to print a octal number

    check this link http://ideone.com/OLXEL7

    printf("%o\n", x); 
    

    Hope this helps