Pages

Tuesday, 16 June 2015

Print binary value using recursion

Print binary value using recursion

Coding:

#include<stdio.h>
void dec_to_bin(int n)
{
if(n!=0)
{
dec_to_bin(n/2);
printf("%d",n%2);
}
}
int main()
{
int x;
printf("Please enter the decimal number:");
scanf("%d",&x);
printf("Binary value is:");
dec_to_bin(x);
return 0;
}

Output:
Please enter the decimal number:35
Binary value is:100011