#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:
Previous Next
#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:
Previous Next
No comments:
Post a Comment