Write a c program to convert a given binary into decimal
write a c program to convert a given binary number into decimal number
#include<stdio.h>
#include<conio.h>
void main()
{
int n,dec=0,base=1,r;
clrscr();
printf("Enter the binary number: ");
scanf("%d",&n);
while(n>0)
{
r=n%10;
dec=dec+r*base;
n=n/10;
base=base*2;
}
printf("The decimal number=%d",dec);
getch();
}
Output:
Enter the binary number: 1100
The decimal number=12
No comments: