C code for conversion of binary to decimal

#include<stdio.h>
#include<math.h>
int main(){
int dec=0,bin,i=0;
printf("enter binary number");
scanf("%d",&bin);
while(bin>0){
dec+=(bin%10)*pow(2,i);
bin=bin/10;
i++;

}
printf("decimal number is %d",dec);
return 0;
}

 

Output

LEAVE A REPLY