.#include <iostream>
using namespace std;
void main()
{
int n1, n;
int dec=0,i=0,j,d;
cout<<"Convert Binary to Decimal:\n ";
cout<<"\n";
cout<<"Input the binary number :";
cin>>n;
n1=n;
while(n!=0)
{ d = n % 10;
dec=dec+d*pow(2,i);
n=n/10;
i++;
}
cout<<"\nThe Binary Number : "<<n1<<"\nThe equivalent Decimal Number is : "<<dec<<endl;
system ("pause");
}
using namespace std;
void main()
{
int n1, n;
int dec=0,i=0,j,d;
cout<<"Convert Binary to Decimal:\n ";
cout<<"\n";
cout<<"Input the binary number :";
cin>>n;
n1=n;
while(n!=0)
{ d = n % 10;
dec=dec+d*pow(2,i);
n=n/10;
i++;
}
cout<<"\nThe Binary Number : "<<n1<<"\nThe equivalent Decimal Number is : "<<dec<<endl;
system ("pause");
}
Test Data :
Input the binary number :1010100
Expected Output :
The Binary Number : 1010100
The equivalent Decimal Number is : 84
Write a program in C++ to convert a binary number into a decimal number using math function. .
Reviewed by Unknown
on
June 11, 2017
Rating:
No comments: