py3-coder / Hacktober_Repo_22

Hacktoberfest 2022 : Repository for open-source contributions towards Hacktoberfest 2022
Apache License 2.0
99 stars 237 forks source link

Create convert binary to decimal.cpp #430

Closed SONIYAPATIDAR closed 1 year ago

SONIYAPATIDAR commented 1 year ago

include

include

using namespace std;

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

}
return ans;

}

int main(){ int n; cout<<"Enter a binary number : "; cin>>n; cout<<"Decimal number of "<<n<<" is "<<base2tobase10(n);

return 0;

}