C Program to Convert Binary Number to Decimal
This program converts binary number to equivalent decimal number.
- //C program to convert binary to decimal
- #include <stdio.h>
- #include <math.h>
- int convert(long long n);
- int main()
- {
- long long n;
- printf("Enter a binary number: ");
- scanf("%d", &n);
- printf("%d in binary = %d in decimal", n, convert(n));
- return 0;
- }
- int convert(long long n)
- {
- int decim = 0, i = 0, remr;
- while (n!=0)
- {
- remr = n%10;
- n /= 10;
- decim += remr*pow(2,i);
- ++i;
- }
- return decim;
- }
Output

Solution not working or have any suggestions? Please send an email to [email protected]
Download Android App