C Program to convert Decimal number into Binary.

 #include<stdio.h>

main()

{

int r,l=0;

long n=0,bin=0,s=0,t;

clrscr();

printf("\nEnter a Decimal Value:\n");

scanf("%ld",&n);

t=n;

while(t>0)

{

r=t%2;

s=s*10+r;

t=t/2;

l++;

}

while(l>0)

{

r=s%10;

bin=bin*10+r;

s=s/10;

l--;

}

printf("\nBinary equivalent of %ld is %ld",n,bin);

getch();

}




Output:

  1. Enter a Decimal Value:

8


Binary equivalent of 8 is 1000


  1. Enter a Decimal Value:

126


Binary equivalent of 126 is 1111110






Post a Comment

Previous Post Next Post