C Program to convert Decimal number To Binary number.


 C PROGRAM



#include<stdio.h>
int main()
{
    int n,number,rem,binary_number=0,base=1;
    printf("Enter a number:");
    scanf("%d",&n);
    number=n;
    while(n>0)
    {
        rem=n%2;
        binary_number=binary_number+rem*base;
        n=n/2;
        base=base*10;
    }
    if(binary_number==1 ||binary_number==0)
{
 printf("Binary equivalent of %d is :000%d", number,binary_number);
 }
    else if(binary_number<100)
{
printf("Binary equivalent of %d is :00%d",number,binary_number);
 }
else if(binary_number>=100 && binary_number<1000)
{
 printf("Binary equivalent of %d is :0%d", number,binary_number);
 }
 else
{
 printf("Binary equivalent of %d is :%d", number,binary_number);
}
    return 0;
}



INPUT && OUTPUT







Post a Comment

0 Comments