Users Online

· Guests Online: 94

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C Program to Convert a Number Decimal System to Binary System using Recursion

The following C program using recursion finds a binary equivalent of a decimal number entered by the user. The user has to enter a decimal which has a base 10 and this program evaluates the binary equivalent of that decimal number with base 2.
Here is the source code of the C program to find the binary equivalent of the decimal number. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
* C Program to Convert a Number Decimal System to Binary System using Recursion
*/
#include <stdio.h>

int convert(int);

int main()
{
int dec, bin;

printf("Enter a decimal number: ");
scanf("%d", &dec);
bin = convert(dec);
printf("The binary equivalent of %d is %d.\n", dec, bin);

return 0;
}

int convert(int dec)
{
if (dec == 0)
{
return 0;
}
else
{
return (dec % 2 + 10 * convert(dec / 2));
}
}


$ cc pgm31.c
$ a.out
Enter a decimal number: 10
The binary equivalent of 10 is 1010.

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.82 seconds
10,836,603 unique visits