fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int num,rem,mul=1,ans=0,ans2;
  7. cout<<"we can create dectimal to binary program/n";
  8. cout<<"Enter the value: ";
  9. cin>>num;
  10.  
  11. while(num){
  12. rem=num%10;
  13. num=num/10;
  14. ans+=rem*mul;
  15. mul*=10;
  16. }
  17.  
  18. mul=1,rem,ans2;
  19. while(ans){
  20. rem=ans%10;
  21. ans/=10;
  22. ans2+=rem*mul;
  23. mul*=2;
  24.  
  25. }
  26. // your code goes here
  27. cout<<ans2;
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 5316KB
stdin
1111
stdout
we can create dectimal to binary program/nEnter the  value: 15