Last active
August 26, 2021 10:55
-
-
Save avii-7/5d606660c2789975d8db62095319f4b4 to your computer and use it in GitHub Desktop.
A positive integer is entered through the keyboard, write a function to find the binary equivalent of this number using recursion.
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> | |
void binary(int); | |
int main() | |
{ | |
int num, place = 1, bin = 0, rem; | |
printf("Enter a number: "); | |
scanf("%d", &num); | |
binary(num); | |
return 0; | |
} | |
void binary(int n) | |
{ | |
if (n != 0) | |
{ | |
binary(n / 2); | |
printf("%d ", n % 2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment