Learn about C program to convert binary to decimal in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
C program to convert binary to decimal
Program:
#include<stdio.h>
#include<math.h>
int main()
{
int bin, dec=0, rem, i=0;
printf("Enter Binary number: ");
scanf("%d",&bin);
while(bin!=0)
{
rem = bin % 10;
dec += (rem * pow(2,i));
bin /= 10;
i++;
}
printf("Decimal = %d ",dec);
return 0;
}
Output:
Enter Binary number: 1100 Decimal = 12
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
C Program to Convert Decimal to Binary using function
C Program to Convert Decimal to Binary