Advertisement
mhdew

Integer to Binary

Mar 27th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.28 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.     int n;
  6.     scanf("%d", &n);
  7.  
  8.     int ar[11111];
  9.     int idx=0;
  10.     int rem;
  11.     while(1){
  12.         if(n==0) break;
  13.         rem=n%2;
  14.         ar[idx]=rem;
  15.         idx++;
  16.         n=n/2;
  17.     }
  18.  
  19.     for(int i=idx-1;i>=0;i--){
  20.         printf("%d", ar[i]);
  21.     }
  22.     printf("\n");
  23.  
  24.     return 0;
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement