0% found this document useful (0 votes)
34 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)
34 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy