Binary to Decimal Conversion(int)


#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int n,d,sum=0,p=0;
clrscr();
printf("enter any no. in binary");
scanf("%d",&n);
while(n>0)
{
d=n%10;
sum=sum+d*pow(2,p);
n=n/10;
p++;
}
printf("\n the decimal equivalent of the number is %d",sum);
getch();
return 0;
}

0 comments:

Post a Comment