C Program to Convert Binary Number to Decimal
#include<stdio.h> #include<conio.h> #include<math.h> void main() { int n, q, rem, s=0, k=0; clrscr(); printf("Enter the Binary number :"); scanf("%d",&n); q=n; while(q>0) { rem=q%10; s=s+rem*pow(2,k); q=q/10; k++; } printf("The Decimal Number is %d",s); getch(); }
Output:
Enter the Binary number :1111
The Decimal Number is 15