HacktoberFest icon indicating copy to clipboard operation
HacktoberFest copied to clipboard

Create convert binary to decimal.cpp

Open SONIYAPATIDAR opened this issue 3 years ago • 0 comments

#include #include <math.h> 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;

}

SONIYAPATIDAR avatar Oct 19 '22 13:10 SONIYAPATIDAR