Tuesday, 11 February 2014

write a program to convert binary to decimal number

/* write a program to convert binary to decimal*/
#include<stdio.h>
main()
{
int n,temp,j=1,sum=0,rem,d;
printf("enter the binary number:");
scanf("%d",&n);
temp=n;
while(n)
{
rem=n%10;
d=rem*j;
sum=sum+d;
j=j*2;
n=n/10;
}
printf("%d",sum);
}

No comments:

Contact Form

Name

Email *

Message *