#include
void main()
{
long int num;
long int rem,bn=0,i,x=1,j;
clrscr();
printf("Enter a Decimal Number:");
scanf("%ld",&num);
for(i=num,j=0;i>0;i=i/2,j++)
{
rem=i%2;
bn=bn+rem*x;
x=x*10;
printf("\nIn %d pass the value of\n",j+1);
printf("variable rem is= %ld bn is %ld x is= %ld\n",rem,bn,x);
}
printf("\n\nFinal Output:\n\n\n");
printf("\nDecimal Number is %ld\n\nBinary Number is %ld",num,bn);
getch();
}
OUTPUT
Enter a Decimal Number:15
Decimal Number is 15
Binary Number is 1111
No comments:
Post a Comment