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

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
Explain function pointer with exapmles.   2
why array index always starts from zero?? TCS 4
main() { int i = -3,j=2,k=0,m; m= ++i || ++j && ++k; printf("%d%d%d",i,j,k,m); } HCL 6
write an algorithm and c program to add two 2x2 matrics   1
how do u find out the number of 1's in the binary representation of a decimal number without converting it into binary(i mean without dividing by 2 and finding out the remainder)? three lines of c code s there it seems...can anyone help   5
Write a C program to multiply tho numbers without using arithmetic operator (+, -, *, /).   1
Which is not valid in C? 1) class aClass{public:int x;} 2) /* A comment */ 3) char x=12;   7
main() { int a=4,b=2; a=b<<a + b>>2; printf("%d", a); } Hcl 8
will the program compile? int i; scanf(%d,i); printf(%d,i);   3
How will you allocate memory to a double pointer ?   2
what is the difference between global variable & static variable declared out side all the function in the file.   2
give an example of type casting by a simple c program TCS 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