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

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is it possible to use curly brackets ({}) to enclose single line code in c program?

801


How can you access memory located at a certain address?

668


write a program in c language to print your bio-data on the screen by using functions.

6252


How can a process change an environment variable in its caller?

657


Why void is used in c?

567






Explain how does flowchart help in writing a program?

635


What are void pointers in c?

575


how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?

1507


What is nested structure?

576


What is ambagious result in C? explain with an example.

2058


Can we declare a function inside a function in c?

591


What is an operator?

658


can anyone please tell about the nested interrupts?

1678


When is a null pointer used?

642


why do some people write if(0 == x) instead of if(x == 0)?

655