Write a recursive function that finds the binary equivalent of an integer
solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <ctype.h> | |
#include <math.h> | |
#include <stdbool.h> | |
void binary(int decimal) | |
{ | |
if(decimal==0){printf("%d",0);} | |
if(decimal>0) | |
{ | |
if(decimal%2==0) | |
{ | |
printf("%d\n",0); | |
binary(decimal/=2); | |
} | |
else | |
{ | |
printf("%d\n",1); | |
binary(decimal/2); | |
} | |
} | |
return; | |
} | |
int main() | |
{ | |
int n; | |
printf("enter decimal value\n"); | |
scanf("%d",&n); | |
printf("binary equivalent of %d = \n",n); | |
binary(n); | |
return 0; | |
} |