cpp program to convert binary to decimal
In this program, you will learn to convert the binary number into a decimal number in cpp programming langauge.
Following is the conversion binary to decimal number
code:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
long num;
cout << "Enter a binary number: ";
cin >> num;
int decimalNumber = 0, i = 0, rem;
while (num!=0)
{
rem = num%10;
num /= 10;
decimalNumber += rem*pow(2,i);
++i;
}
cout << decimalNumber << " in decimal";
return 0;
}
Output:
Enter a binary number: 101
5 in decimal
Comments
Post a Comment