Skip to content

Instantly share code, notes, and snippets.

@avii-7
Last active August 26, 2021 10:55
Show Gist options
  • Save avii-7/5d606660c2789975d8db62095319f4b4 to your computer and use it in GitHub Desktop.
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.
#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