C Program to Convert Binary to Decimal number | Binary to Decimal Conversion in C

C Program to Convert Binary to Decimal number | Binary to Decimal Conversion in C | C Language Assignment to convert Binary Value to Decimal Value 



#include
#include
#include

void bin_dec(long int num)   // Function declaration
{
long int rem,sum=0,power=0;
while(num>0)
 {
 rem = num%10;
 num = num/10;
 sum = sum + rem * pow(2,power);
 power++;
 }

printf("\n Converted Decimal number is : %d",sum);
}



// END of Function




void main()
{
long int num;
clrscr();

printf(" Please Enter the Binary number (0 and 1 only): \n");
scanf("%ld",&num);

bin_dec(num);

getch();
}


No comments:

Post a Comment