-5

How would I write a recursive solution in C that does this? For example, if I input 9, it should output 00001001

1 Answers1

1
#include <stdio.h>
#include <stdint.h>

void p(uint8_t n, int times){
    if(times){
        p(n >> 1, times-1);
        putchar("01"[n & 1]);
    }
}

void print_bin8(uint8_t num){
    p(num, 8);
}

int main(void){
    print_bin8(9);
    return 0;
}
BLUEPIXY
  • 39,699
  • 7
  • 33
  • 70