How to convert decimal to binary in C using recursion??
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
What is the purpose of the code, and is there any problem with it? unsigned int f( unsigned n ) { return –n & 7; }
write a c program to do the following: a) To find the area of a triangle. b) To convert the temperature from Fahrenheit to Celsius. c) To convert the time in hours : minutes : seconds to seconds.
What are dangling pointers? How are dangling pointers different from memory leaks?
what is the output for the code : main() { int i,j; printf("%d %d ",scanf("%d%d",&i,&j)); }
can you explain in brief what is "r+" mode in a file... i know that it si used to read and modify rhe existing content.... but explalanation about the file pointer in "r+" mode i wann to know???????????
Write a program to find the smallest and largest element in a given array in c language
The C language terminator is a.semicolon b.colon c.period d.exclamation mark
Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?
Is c easy to learn?
what's the o/p int main(int n, char *argv[]) { char *s= *++argv; puts(s); exit(0); }
Explain About fork()?
Should a function contain a return statement if it does not return a value?