Thursday, July 4, 2013

Convert a Decimal number into Binary number

#include <stdio.h>
int main(void)
{
    int number,mod,base = 1,total = 0 ;


    printf("\nEnter a decimal number and I'll let you know Binary of it : ");
    scanf("%d",&number);


    while ( number != 0)
    {
       mod = number % 2 ;
       total = total + mod * base ;
       number = number/2;
       base = base * 10;
    }
 
    printf("\nBinary number of decimal %d is %d",number,total);


    return 0;
 
}

No comments: