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

how can use subset in c program and give more example

0 Answers  


What is the use of function in c?

0 Answers  


What is the use of extern in c?

0 Answers  


what is the role you expect in software industry?

2 Answers   HCL, Wipro,


Are global variables static in c?

0 Answers  


Write a Program to find whether the given number or string is palindrome.

0 Answers   InterGraph,


How can I find leaf node with smallest level in a binary tree?

1 Answers  


What are data types in c language?

0 Answers  


What are the average number of comparisons required to sort 3 elements?

2 Answers   DRDO,


Sir,please help me out with the output of this programme:- #include<stdio.h> #include<conio.h> void main() { int a=18,b=12,i; for(i=a<b?a:b;a%i||b%i;i--); printf("%d %d",i); }

4 Answers  


What are the uses of a pointer?

0 Answers  


Is it better to use malloc() or calloc()?

0 Answers   Aspire, Infogain,


Categories