/*convert binary to decimal */
#include<stdio.h>
#include<conio.h>
void main()
{
int j=1,dec=0,d,n,rem;
clrscr();
printf("Enter a binary number :");
scanf("%d",&n);
while(n>0)
{
rem=n%10;
d=rem*j;
dec+=d;
j*=2;
n/=10;
}
printf("decimal number is = %d",dec);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int j=1,dec=0,d,n,rem;
clrscr();
printf("Enter a binary number :");
scanf("%d",&n);
while(n>0)
{
rem=n%10;
d=rem*j;
dec+=d;
j*=2;
n/=10;
}
printf("decimal number is = %d",dec);
getch();
}
No comments:
Post a Comment