Achlesha / hactoberFest2022

For people to contribute in hacktoberfest 2022
https://github.com/Achlesha/hactoberFest2022
18 stars 61 forks source link

Create convert decimal to binary.cpp #57

Open SONIYAPATIDAR opened 2 years ago

SONIYAPATIDAR commented 2 years 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;

}