dikshantrajput / Hacktoberfest-accepted-2022

This repository is for everyone who wants to participate in Hacktoberfest 2022. Anyone can contribute/add quality code or projects for your Swags (T- Shirt), must be relevant that can add some value to this repository
114 stars 458 forks source link

Create convert decimal to binary.cpp #666

Open SONIYAPATIDAR opened 1 year ago

SONIYAPATIDAR commented 1 year ago

include

include

using namespace std;

int base10tobase2(int n){ int count=0, ans=0 ,rem ; while(n!=0){ rem=n%2; ans+=pow(10,count)*rem; count++; n/=2;

}
return ans;

}

int main(){ int n; cout<<"Enter a decimal number : "; cin>>n; cout<<"Binary number of "<<n<<" is "<<base10tobase2(n)<<endl;

return 0;

}