C Program to Convert Binary to Decimal

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    long int binary_num, decimal_num=0, i=1, rem;
    printf("\n Enter any binary number : ");
    scanf("%ld",&binary_num);
    while(binary_num!=0)
    {
        rem=binary_num%10;
        decimal_num=decimal_num+rem*i;
        i=i*2;
        binary_num=binary_num/10;
    }
    printf("\n Equivalent decimal value = %ld",decimal_num);
    getch();
}

Run1:
Run2:

No comments:

Post a Comment

100 C Programs with Code and Output

Program 1: C Program To Read Two Numbers And Print The Sum Of Given Two Numbers. Program 2: C Program To Read Three Numbers And Prin...