Recent Posts

9-latest-250px-course

Write a C program to Convert the given Binary Number into Decimal

Write a C program to Convert the given Binary Number into Decimal



Program:-     

#include <stdio.h>

#include <math.h>

int binary_to_decimal(long int n)
{
int decimal = 0, i = 0, remainder;
while (n!=0)
{
remainder = n%10;
n /= 10;
decimal += remainder*pow(2,i);
++i;
}
return decimal;
}

int main()
{
long int n;
printf(“Enter a binary number: “);
scanf(“%ld”, &n);
printf(“\nDecimal number : %d\n “, binary_to_decimal(n));
return 0;
}

Output:-

....
SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment