<>

Decimal to Binary Conversion C Program


C Program which convert decimal number to binary numbers:

#include <stdio.h>
main()
{
    int n, c, k;

    printf("Enter an integer in decimal number system: ");
    scanf("%d",&n);

    printf("%d in binary number system is: ",n);

    for (c = 31; c >= 0; c--)
    {
        k = n >> c;

        if (k & 1)
            printf("1");
        else
            printf("0");
    }
}

Also by Making Function of it:

#include <stdio.h>
void dectobin(int);
main()
{
    int n;

    printf("Enter an integer in decimal number system: ");
    scanf("%d",&n);

    dectobin(n);
}
void dectobin(int n)
{
    int c,k;

    printf("%d in binary number system is: ",n);

    for (c = 31; c >= 0; c--)
    {
        k = n >> c;

        if (k & 1)
            printf("1");
        else
            printf("0");
    }
}

Rate this posting:
{[['']]}

0 comments:

Post a Comment

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

 
TOP