arox14

Decimal to Binary

Oct 21st, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.27 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {clrscr();
  5. int d,n,b[10],i=0,r,j;
  6. cout<<"Enter a decimal number";
  7. cin>>d;
  8. n=d;
  9. while (n)
  10. {r=n%2;
  11. b[i]=r;
  12. i++;
  13. n=n/2;
  14. }
  15. cout<<"The binary equivalent of the number is:";
  16. for(j=i-1;j>=0;j--)
  17. cout<<b[j];
  18. getch();
  19. }
Add Comment
Please, Sign In to add comment