Wednesday, 26 August 2015

Programming in C to convert the binary form of digits to decimal form of a number

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<process.h>
void main()
{
long n;
int x,y=0,p=0;
printf("\nEnter Binary number: ");
scanf("%d",&n);
while (n!=0)
{
x=n%10;
if (x>1||x<0)
{
printf("\nInvalid number.");
exit(1);
}
y=y+x*pow(2,p);
n=n/10;
p++;
}
printf("\n Its Decimal number is %d.",y);
getch();
}

No comments:

Post a Comment