Program to print binary equivalent of a decimal number Note MSP should print first and LSB last.

main()
{
int n;
printf("\n Enter any number:");
scanf("%d", &n); dec2bin(n);
}


dec2bin(int n)
{
if(n == 0)
return ; else
{
dec2bin (n/2);
printf("%d", n%10);
}
}

6 comments:

  1. ..it will not work..

    ReplyDelete
  2. ...can you make a sample program that will input an integer and displays the binary equivalent?

    ReplyDelete
  3. make a sample that will input an integer and displays the binary equivalent ?

    ReplyDelete
  4. yes sure frind please mail me details to hellopankajin@rediff.com i will mail u solution...

    ReplyDelete
  5. dec2bin(int n)
    {
    if(n == 0)
    return ; else
    {
    dec2bin (n/2);
    printf("%d", n%2);
    }
    }

    i think now its right

    ReplyDelete
  6. #include

    main()
    {
    unsigned int num;
    int i;
    scanf("%u",&num);
    for(i=0;i<32;i++)
    printf("%d",(num<<i & 1<<31)?1:0);


    }

    ReplyDelete