Binary To Decimal In C - Math Traders

Latest

Binary To Decimal In C

In This C Tutorial I am gonna show you that how you can write a code in c programming language to convert a binary number into a decimal number:

Given blow is an example where i have written a piece of code to convert a binary number into decimal number.

binary input 1010
decimal output 10


#include<stdio.h>
#include<math.h>
int main()
{
   int bnum,count=0,sum,rem;
   printf("enter a binary number");
   scanf("%d",&bnum);
   sum =0;
   while(bnum>0)
   {
       rem=bnum%10;
       sum = sum+rem*pow(2,count);
       bnum = bnum/10;
       count++;
   }
   printf("your decimal no is :%d",sum);

    return 0;
}

No comments:

Post a Comment