Program to Convert a binary number to a decimal number

#include<stdio.h>
#include<conio.h>

int main()

{

int n, nsave, rem, d, j = 1, decimal = 0;
printf(“Enter the number in binary”);
scanf_s(“%d”, &n);
nsave = n;
while (n>0)
{
rem = n%10;
d = rem*j;
decimal= decimal+d;
j = j * 2;
n =n/ 10;
}
printf(“Binary number = %d, Decimal number = %d\n”, nsave, decimal);

return 0;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *