C++ program to convert Decimal to Binary

#include <iostream>
using namespace std;

int main()
 {
 int sumStore=0,base=1,dec,num,rem;

 cout<<"Enter a decimal number : ";
 cin>>num;
 dec=num;

  while(num!=0)
    {
      rem=num%2;
      sumStore=sumStore+(rem*base);
      base=base*10;
      num=num/2;

    }

 cout<<"\nThe binary Equivalent of Decimal No "<<dec<<" is = "<<sumStore<<endl;


 return 0;
}

No comments:

Post a Comment