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

Give me the code of in-order recursive and non-recursive.

0 Answers   DELL,


write a Program to dispaly upto 100 prime numbers(without using Arrays,Pointer)

26 Answers   ADITI, iFlex, Infosys, Oracle, TCS, Unicops, Wipro,


A c program to display count values from 0 to 100 and flash each digit for a secong.reset the counter after it reaches 100.use for loop,. pls guys hepl me.. :(

0 Answers  


Explain following declaration int *P(void); and int (*p)(char *a);

3 Answers  


What is meant by inheritance?

0 Answers  






difference between semaphores and mutex?

1 Answers  


Why should I use standard library functions instead of writing my own?

0 Answers  


What is an arrays?

0 Answers  


A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.

0 Answers  


When was c language developed?

0 Answers  


How to implement variable argument functions ?

1 Answers   HP,


the maximum value that an integer constant can have is a) -32767 b) 32767 c) 1.701e+38 d) -1.7014e+38

1 Answers  


Categories