0% found this document useful (0 votes)
30 views

Binary Convert Using Recursion

This C program contains functions to convert a decimal number to binary. The main function prompts the user to enter a decimal number, calls the binary function to perform the conversion, and prints the resulting binary value. The binary function recursively calculates the binary representation by taking the number modulo 2 at each iteration, multiplying the remainder by an increasing place value, and recursively calling itself on the integer portion until the number reaches 0.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Binary Convert Using Recursion

This C program contains functions to convert a decimal number to binary. The main function prompts the user to enter a decimal number, calls the binary function to perform the conversion, and prints the resulting binary value. The binary function recursively calculates the binary representation by taking the number modulo 2 at each iteration, multiplying the remainder by an increasing place value, and recursively calling itself on the integer portion until the number reaches 0.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

File: /home/aditya/binary-convert.

c
#include<stdio.h>
int binary(int);
void main()
{
int n,p;
printf("Enter a number in decimal : ");
scanf("%d",&n);
p=binary(n);
printf("The value in binary is %d\n",p);
}
int binary(int n)
{
static int p,r,f=1;
if(n!=0)
{
r=n%2;
p=p+r*f;
f=f*10;
binary(n/2);
}
return p;
}

Page 1 of 1

You might also like