brel-logo-white brel-logo-white
  • Travel
  • Case Study
  • How to
  • Technology
  • More
    • Sports
    • Health
    • Articles
    • Review
Notification
  • HomeHome
  • Finance
  • Health
  • Lifestyle
  • Sports
  • Contact Us
BreldigitalBreldigital
  • HomeHome
  • Finance
  • Health
  • Lifestyle
  • Sports
  • Contact Us
Search
  • Quick Access
    • Home
    • History
    • My Saves
    • My Interests
    • My Feed
  • Categories
    • Travel
    • Sports
    • Health

Top Stories

Explore the latest updated news!

Stephanie puts 30 cubes in a box

Which statement correctly describes the process that occurs in the thylakoid?

Which point is on the line that passes through point h and is perpendicular to line fg?

Stay Connected

Find us on socials
248.1k Followers Like
61.1k Followers Follow
165k Subscribers Subscribe
Breldigital > Blog > ds > Print binary number in c
ds

Print binary number in c

By John Published November 10, 2022
Share

This is a C program to print binary equivalent of an integer using recursion.

Problem Description
This C program, using recursion, finds the binary equivalent of a decimal number entered by the user.

Problem Solution
Decimal numbers are of base 10 while binary numbers are of base 2.

Program/Source Code
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

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);
}
}

Runtime Test Cases

$ gcc binary_recr.c -o binary_recr
$ a.out
Enter a decimal number: 10
The binary equivalent of 10 is 1010

TAGGED: Print binary number in c
John November 10, 2022 November 10, 2022

Search

brel-logo-white brel-logo-white
Explore a wide range of brands and categories with our comprehensive coverage, and stay up-to-date with the latest news and trends by subscribing to our updates.
Categories:
  • Entertainment
  • Travel
  • Sport
  • Contact Us

Quick Links

  • My Feed
  • My Interests
  • History
  • My Saves

About US

  • Adverts
  • Our Jobs
  • Term of Use

© 2023 Brel Digital All Rights Reserved. All logos and images used on this website are registered trademarks of their respective companies

Welcome Back!

Sign in to your account

Lost your password?