Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. ///binary conversion using recursion
  2. #include<bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. void bin(int n)
  7. {
  8.     if(n<=0) return;
  9.     bin(n/2);
  10.     printf("%d",n%2);
  11. }
  12.  
  13. int main()
  14. {
  15.     int x;
  16.     while(scanf("%d",&x)!=EOF)
  17.     {
  18.         if(x==0)
  19.         {
  20.             printf("0\n");
  21.             continue;
  22.         }
  23.  
  24.         bin(x);
  25.         printf("\n");
  26.     }
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement