Computer Science, asked by doll677435, 10 months ago

write a program in recursion to convert decimal to binary​

Answers

Answered by rakeshchennupati143
1

Answer:

#include <stdio.h>

int convert(int);

int main(){

   int dec, bin;

   printf("Enter a decimal number: ");

   scanf("%d", &dec);

   bin = convert(dec);

   printf("The binary equivalent of %d is %d.\n", dec, bin);

   return 0;

}

int convert(int dec){

   if (dec == 0){

       return 0;

   }else{

       return (dec % 2 + 10 * convert(dec / 2));

   }

}

Output:

Enter a decimal number: 10

The binary equivalent of 10 is 1010.


doll677435: actually i wanted in java
rakeshchennupati143: ok i dont have any edit option so i posting ans here
rakeshchennupati143: i think you will not understand it but i dont know what to do i wrote the code in java
doll677435: no problem
Similar questions