Convert the Binary Number into Decimal In C

In this tutorial, we will learn how to convert the binary number to the decimal using C Programming Language.

C Program to Convert the given Binary Number into Decimal

#include <stdio.h>

/*Learn C Programming at*/
 void main()

    int  num, B_value, D_value= 0, base = 1, r;
    printf("Please enter a binary number(1s and 0s) \n");
    scanf("%d", &num);
    B_value = num;
    while (num > 0)
        r = num % 10;
        D_value= D_value+ r * base;
        num = num / 10 ;
        base = base * 2;
    printf("Binary number:  %d \n", B_value);
    printf("Decimal equivalent is : %d \n", decimal_val);


Leave a Comment

Your email address will not be published. Required fields are marked *