fork(3) download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include<math.h>
  4.  
  5. int main()
  6. {
  7.  
  8. int a,i;
  9. scanf("%d", &a);
  10. int n = (int)(ceil(log2(a+1)));
  11. int str[n];
  12.  
  13. printf("Binary of %d is : ", a);
  14.  
  15. for(i=n-1;i>=0;i--) {
  16. str[i]=a%2; // ***** the binary value is stored here
  17. a /= 2;
  18. }
  19.  
  20. for(i=0;i<n;i++)
  21. printf("%d",str[i]);
  22. printf("\n");
  23. return 0;
  24. }
Success #stdin #stdout 0s 2856KB
stdin
8
stdout
Binary of 8 is : 1000