Digital Conversion from Binary 2 Decimal
#include<iostream.h>
#include<conio.h>
void main()
{
char ch;
do
{
int n,rem,sum=0,j=1;
cout<<"\nEnter the binary value:";
cin>>n;
while(n>0)
{
rem=n%10;
sum+=rem*j;
j*=2;
n=n/10;
}
cout<<"\nDecimal value is:"<<sum;
cout<<"\nDo u want to continue:";
cin>>ch;
}while(ch!='0');
getch();
}
output#include<conio.h>
void main()
{
char ch;
do
{
int n,rem,sum=0,j=1;
cout<<"\nEnter the binary value:";
cin>>n;
while(n>0)
{
rem=n%10;
sum+=rem*j;
j*=2;
n=n/10;
}
cout<<"\nDecimal value is:"<<sum;
cout<<"\nDo u want to continue:";
cin>>ch;
}while(ch!='0');
getch();
}
No comments:
Post a Comment