#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
int a[10],i,no,sum=0,rem,j,k=0;
clrscr();
cout<<"Enter Binary No:";
cin>>no;
i=0;
while(no>0)
{
a[i]=no%10;
no=no/10;
i++;
}
for(j=0;j<i;j++)
{
sum=sum+a[j]*pow(2,k);
k++;
}
cout<<"Decimal NO:"<<sum;
getch();
}
Subscribe to:
Post Comments (Atom)
Related Post
Array:
String functions:
General (Loops-for/while)
dosent work!!!!
ReplyDeleteshowing errors!!!!
ReplyDeleteint main()
ReplyDelete{
int n,r,sum=0;
cout<<"N = ";
cin>>n;
for(int i=0;n>0;i++)
{
r = n%10;
sum = sum+r*pow(2,i);
n = n/10;
}
cout<<"decimal : "<<sum;
}
when input=0010,it is giving output 8
ReplyDeleteGood
ReplyDeleteHere is a link for C/C++ programs and pointer programs. This may be useful for you.
C Programs
C++ Programs
C++ program to convert decimal to binary
ReplyDeletesuper