Advertisement
hazimsimaan

Untitled

Jun 25th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. void print_base_2(int num);
  3. int main()
  4. {
  5. int x;
  6. scanf("%d",&x);
  7. print_base_2(x);
  8. return 0;
  9. }
  10. void print_base_2(int num)
  11. {
  12.  
  13. if(num==1)
  14. {
  15. printf("1-1");
  16. return ;
  17. }
  18. if (num==0)
  19. {
  20. printf("0-0");
  21. return ;
  22.  
  23. }
  24. if(num%2)
  25. printf("%d",num%2);
  26.  
  27. else
  28. printf("0");
  29. print_base_2(num/2);
  30.  
  31. if(num/2==1)
  32. {
  33. printf("1");
  34. }
  35. if (num/2==0)
  36. {
  37. printf("0");
  38.  
  39. }
  40. printf("%d",num%2);
  41.  
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement