C program to convert Binary number into Decimal number
Program
#include <stdio.h>
int main()
{
int binary, decimal = 0, base = 1, remainder;
printf("Enter Binary number to convert in Decimal : ");
scanf("%d", &binary);
int temp = binary;
while(temp > 0)
{
remainder = temp % 10;
decimal = decimal + remainder * base;
temp = temp / 10;
base = base * 2;
}
printf("The Decimal number of %d is : %d", binary, decimal);
return 0;
}
Output 1
Enter Binary number to convert in Decimal : 1111
The Decimal number of 1111 is : 15
Output 2
Enter Binary number to convert in Decimal : 1010
The Decimal number of 1010 is : 10
0 Comments