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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a protocol in c?

634


the 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?

657


How to declare pointer variables?

783


How will you declare an array of three function pointers where each function receives two ints and returns a float?

888


In c programming language, how many parameters can be passed to a function ?

738






What is modifier & how many types of modifiers available in c?

701


What is the purpose of the following code? Is there any problem with the code? void send(int count, short *to, short *from) { /* count > 0 assumed */ register n = (count + 7) / 8; switch (count % 8) { case 0: do { *to = *from++; case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; } while (--n > 0); } }

2092


How do you do dynamic memory allocation in C applications?

725


What is Dynamic memory allocation in C? Name the dynamic allocation functions.

700


What is an array? What the different types of arrays in c?

749


Write a function expand(s1,s2) that expands shorthand notations like a-z in the string s1 into the equivalent complete list abc...xyz in s2 . Allow for letters of either case and digits, and be prepared to handle cases like a-b-c and a-z0-9 and -a-z. z-a:zyx......ba -1-6-:-123456- 1-9-1:123456789987654321 a-R-L:a-R...L a-b-c:abbc

5188


How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same

748


What is the difference between memcpy and memmove?

687


Which is not valid in C a) class aClass{public:int x;}; b) /* A comment */ c) char x=12;

711


Describe the header file and its usage in c programming?

708