Algorithms_in_C  1.0.0
Set of algorithms implemented in C.
decimal_to_binary_recursion.c File Reference

Convert decimal to binary using recursion algorithm. More...

#include <assert.h>
Include dependency graph for decimal_to_binary_recursion.c:

Functions

int decimal_to_binary (unsigned int number)
 Decimal to binary using recursion algorithm. More...
 
void test ()
 Test function.
 
int main ()
 Driver Code.
 

Detailed Description

Convert decimal to binary using recursion algorithm.

Function Documentation

◆ decimal_to_binary()

int decimal_to_binary ( unsigned int  number)

Decimal to binary using recursion algorithm.

For example, if number = 5, the function returns the decimal integer 101.

Parameters
numberpositive integer number to convert
Returns
integer with digits representing binary value representation of number.
15 {
16  return number == 0 ? 0 : number % 2 + 10 * decimal_to_binary(number / 2);
17 }
int decimal_to_binary(unsigned int number)
Decimal to binary using recursion algorithm.
Definition: decimal_to_binary_recursion.c:14