Decimal to binary conversion using function

Program:

#include<stdio.h>
void dec2bin(int);
int main()
{
int dec;
printf("Enter Positive Integer Number: ");
scanf("%d",&dec);
dec2bin(dec);
return 0;
}
void dec2bin(int m)
{
    int bin[10],i=0,j;
    while(m>0)
    {
    bin[i]=m%2;
    m=m/2;
    i++;
}
for(j=i-1;j>=0;j--)
{
printf("%d",bin[j]);
}
}

Output:



No comments:

Post a Comment

x^y using recursion

Program: #include<stdio.h> int power(int a,int b); int main() { int x,y,ans; printf("Enter x and y:\n "); scanf(...