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);
}
}

Related Links :

7 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. i think decimal means 1.45454 lyk that na.. for that how this program will work. for example if we put float instead of int how it will process..

    ReplyDelete
  7. #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


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!