Friday, 4 December 2015

Converting Decimal number to Binary number with while loop

This code is using for converting Decimal number to Binary number.

Sample Input     : 15
            Output  : 1111

 

 

Code is :

 #include<stdio.h>

int main()
{
    int Num1,b;

    printf("\n\tEnter Number to find binary : ");
    scanf("%d",&Num1);

    printf("\n\tBinary is : ");
    while(Num1!=0)
    {
    b=Num1%2;
    printf(" %d",b);
    Num1=Num1/2;

    }

}

 

No comments:

Post a Comment