How to convert decimal to binary in C using recursion??

Answers were Sorted based on User's Feedback



How to convert decimal to binary in C using recursion??..

Answer / jaguar

Please check the following program buddy,
Just save it as .c and run it you got what you want

# include <stdio.h>

void Rec_Dec_To_Bin (int num);

void main ()
{
int num;
int base;

printf ("Enter the decimal number to convert it binary.\n");
scanf ("%d", &num);


printf ("The number in decimal is : %d\n", num);
printf ("\n");

printf ("The %d in binary is : ", num);
Rec_Dec_To_Bin (num);

printf ("\n\n");

}

void Rec_Dec_To_Bin (int num)
{

if (((num / 2) != 0) && (num > 1))
{
Rec_Dec_To_Bin ((num / 2));
}

printf ("%d", (num % 2));

}

Is This Answer Correct ?    21 Yes 17 No

How to convert decimal to binary in C using recursion??..

Answer / sd

#include<stdio.h>
int bin(int);
main()
{ int n,r;
printf("Enter the number in decimal:");
scanf("%d",&n);
r=bin(n);
printf("The binary equivalent is:%d",r);
getch();
}
int bin(int x)
{ int k;
if(x==0)
return 0;
k=x%2;
int j=k+(10*bin(x/2));
return j;
}

Is This Answer Correct ?    3 Yes 3 No

How to convert decimal to binary in C using recursion??..

Answer / rajaas tahir

# include <stdio.h>
#include<conio.h>
void Bin (int num);

int main (void)
{
int num;
int base;

printf ("Enter the decimal number to convert it binary.\n");
scanf ("%d", &num);

printf ("The %d in binary is : ", num);
Bin (num);
getch();
}

void Bin (int num)
{

int a, b;
a=num/2;
if ((a!= 0) && (num > 1))
{
printf("%d",(num%2));
Bin (num / 2);
}

}

Is This Answer Correct ?    3 Yes 14 No

How to convert decimal to binary in C using recursion??..

Answer / sagar

by dividing that number by 2..

Is This Answer Correct ?    4 Yes 16 No

Post New Answer

More C Interview Questions

What is the difference function call by value & function call by reference?

6 Answers  


What are the Advantages of using macro

0 Answers  


Write a program that his output * *** *****

1 Answers  


What is volatile variable in c with example?

0 Answers  


Here is a neat trick for checking whether two strings are equal

0 Answers  


What is pivot in c?

0 Answers  


What is volatile in c language?

2 Answers   HCL, TCS,


Why is extern used in c?

0 Answers  


What are the advantages of using macro in c language?

0 Answers  


What is structure data type in c?

0 Answers  


Explain what is the difference between null and nul?

0 Answers  


Why does this code crash?

0 Answers  


Categories