Thursday, July 2, 2015

Decimal to binary by function

#include<stdio.h>
void binary(int decimal)

{
    int r,bin=0,p=1;

    while(decimal!=0)
    {
       r=decimal%2;

       bin=bin+p*r;

       p=p*10;

       decimal=decimal/2;


    }
    printf("%d",bin);

}
int main()
{
    int a;

    scanf("%d",&a);

    binary(a);

    return 0;
}

No comments:

Post a Comment