I wrote code for getting binary form of an integer. It works well for inputs like 1 or 10. However, it is failing for inputs like 256. (It gives 0000000 s output and misses the one).

```
#include <stdio.h>
#include <math.h>

int number_of_binary_digits_required(int n){

return ceil(log(n))+1;

}

void print_array(int * a, int n){

    int i = 0;
    for (;i<n;i++){
        printf("%d\t", a[i]);
    }

}

int main(){

int num = 256;
int binary[100];
int n = number_of_binary_digits_required(num);
int bin_digits = n-1;

while (num){

   int temp = num%2;
   num = num / 2;
   binary[bin_digits] = temp;
   //printf("%d\n", bin_digits);
   bin_digits--;

}

print_array(binary, n);

//printf("%d", number_of_binary_digits_required(num));
//for(bin_digits = 0;bin_digits < number_of_binary_digits_required(num);bin_digits++)
//printf("%d",binary[bin_digits]);

}

```

Why is the issue coming and how to resolve it?

Thanks you!