C program to Decimal to Binary by Recursion

Below is C program to Decimal to Binary by Recursion.

Program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* Binary by recursion */
 
#include<stdio.h>
void binary(long);
int main()
{
 long n;
 printf("Type a value : ");
 scanf("%ld",&n);
 binary(n);
 return 0;
}
 
void binary(long n)
{
 if(n>1)
  binary(n/2);
 printf("%ld",n%2);
}

No comments:

Post a Comment