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;

    }

}

 

Reverse an integer number with while loop

This code is using for revese an integer number.

Sample Input     : 12345
            Output  : 54321

Code is : 

#include<stdio.h>

int main()
{
    int Num1,b;

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

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

    }

}