C Program to convert binary to decimal number

 In this example, we will learn how to convert the binary to decimal number in the c programming language. Following is the solution to the problem.


#include <math.h>

#include <stdio.h>

int main() {

    long long num,original;

    printf("Enter a binary number: ");

    scanf("%lld", &num);



    int deci = 0, i = 0, remainder;

    while (num != 0) {

        remainder = num % 10;

        num /= 10;

        deci += remainder * pow(2, i);



    printf("%lld in binary = %d in decimal", original, deci);

    return 0;



Enter a binary number: 111

111 in binary = 7 in decimal


Hire a programmer

Popular posts from this blog

CSS selector

C program to convert decimal to binary number