ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Software >> Programming Languages >> C
 
 


 

 
 C interview questions  C Interview Questions (2248)
 C++ interview questions  C++ Interview Questions (1106)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (644)
Question
How to convert decimal to binary in C using recursion??
 Question Submitted By :: Fernandosoraes
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How to convert decimal to binary in C using recursion??
Answer
# 1
by dividing that number by 2.. 
Is This Answer Correct ?    4 Yes 14 No
Sagar
 
  Re: How to convert decimal to binary in C using recursion??
Answer
# 2
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 ?    20 Yes 15 No
Jaguar
 
 
 
  Re: How to convert decimal to binary in C using recursion??
Answer
# 3
# 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 ?    2 Yes 12 No
Rajaas Tahir
 
  Re: How to convert decimal to binary in C using recursion??
Answer
# 4
#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 ?    1 Yes 0 No
Sd
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
What is the memory allocated by the following definition ? int (*x)(); ADITI 2
Unsigned char c; for ( c=0;c!=256;c++2) printf("%d",c); No. of times the loop is executed ? Mascot 7
what is const volatile?   2
HOW DO YOU HANDLE EXCEPTIONS IN C? AppLabs 2
how can i calculate mean,median,mode by using c program HCL 1
count the numbers between 100 and 300, that star with 2 and ends with 2 Mind-Tree 5
what is bitwise operator? IBM 1
What is the mean of this statement:: if(int i=0 * i=9) HCL 2
f(*p) { p=(char *)malloc(6); p="hello"; return; } main() { char *p="bye"; f(p); printf("%s",p); } what is the o/p? Hughes 7
how to find the binary of a number? Infosys 10
How do we swap or interchange any 2 numbers without using Temporary variable...Anybody can pls answer it.. Thanks in Advance   8
Can I pass constant values to functions which accept structure arguments?   2
 
For more C Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com