C Program Binary to Decimal Number

By | March 15, 2020

C Program Binary to Decimal Number Converter

C Program convert binary to decimal number

C Program convert binary to decimal number

 

/* Write a C program to input a binary number,
 and convert into correspondin Decimal number 
     www.easycodebook.com
*/ 
#include<stdio.h>
#include<math.h>

int main()
{
	long int binNum,rem,n,i,decimal;
	printf("Enter a Binary Number:");
	scanf("%ld",&binNum);
	i=0;
	decimal=0;
	for(n=binNum;n!=0;n=n/10)
	{
		rem=n%10;
		decimal=decimal+rem*pow(2,i);
		i++;
	}
	printf("Decimal Number:%ld ",decimal);
	return 0;
}

Output 1:

Enter a Binary Number:101
Decimal Number:5

Output 2:

Enter a Binary Number:110110
Decimal Number:54

Output 3:

Enter a Binary Number:1111
Decimal Number:15

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *