Users Online
· Guests Online: 40
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
C Program to Print Binary Equivalent of an Integer using Recursion
This C program, using recursion, finds the binary equivalent of a decimal number entered by the user. Decimal numbers are of base 10 while binary numbers are of base 2.
Here is the source code of the C program to display a linked list in reverse. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C Program to Print Binary Equivalent of an Integer using Recursion
*/
#include <stdio.h>
int binary_conversion(int);
int main()
{
int num, bin;
printf("Enter a decimal number: ");
scanf("%d", &num);
bin = binary_conversion(num);
printf("The binary equivalent of %d is %d\n", num, bin);
}
int binary_conversion(int num)
{
if (num == 0)
{
return 0;
}
else
{
return (num % 2) + 10 * binary_conversion(num / 2);
}
}}
$ gcc binary_recr.c -o binary_recr
$ a.out
Enter a decimal number: 10
The binary equivalent of 10 is 1010
Here is the source code of the C program to display a linked list in reverse. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C Program to Print Binary Equivalent of an Integer using Recursion
*/
#include <stdio.h>
int binary_conversion(int);
int main()
{
int num, bin;
printf("Enter a decimal number: ");
scanf("%d", &num);
bin = binary_conversion(num);
printf("The binary equivalent of %d is %d\n", num, bin);
}
int binary_conversion(int num)
{
if (num == 0)
{
return 0;
}
else
{
return (num % 2) + 10 * binary_conversion(num / 2);
}
}}
$ gcc binary_recr.c -o binary_recr
$ 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.