program in c to binary number to a
decimal number
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
long int n,res=0,i=0;
clrscr();
printf(“ enter the binary digit “);
scanf(“%d”,&n);
for(;n>0;)
{
r=n%10;
res+=r*pow(2,i);
i++;
n=n/10;
}
printf(“decimal equivalent is %d”, res);
return 0;
}
output:
enter binary digit:111
decimal equivalent is:7
No comments:
Post a Comment