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 |
Create a simple code fragment that will swap the values of two variables num1 and num2.
In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)
Stimulate calculators to perform addition,subtraction,multiplication and division on two numbers using if/else statement?
Read N characters in to an array . Use functions to do all problems and pass the address of array to function. 2. Enter alphanumeric characters and form 2 array alphaets and digits.Also print the count of each array.
helllo sir , what is the main use of the pointer ,array ,and the structure with the example of a programe
can we execute the program with the object file
program to find the magic square
How would you write qsort?
if a five digit number is input through the keyboard, write a program to calculate the sum of its digits. (hint:-use the modulus operator.'%')
Combinations of fibanocci prime series
What is void main ()?
what is difference between overriding and overloading?