Last active
April 21, 2020 11:27
-
-
Save ABD-01/4b98b51b7048fdf7d744b194e420ec2a to your computer and use it in GitHub Desktop.
Read an integer from user and out it in binary format. Write a recursive function.
This file contains hidden or 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 <math.h> | |
int binary(int ); | |
int main() | |
{ | |
int num; | |
printf("Enter a num: "); | |
scanf(" %i",&num); | |
printf("The output in Binary is: %i \n",binary(num)); | |
return 0; | |
} | |
int binary(int x) | |
{ | |
if(x==0) | |
return 0; | |
int dig=log(x) / log(2); | |
return (x%2)*pow(10,dig) + binary(x/2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment