Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

recursion to convert decimal to binary

#include <stdio.h>
 
int decimal_binary(int n)
{
    if (n==0)
        return 0;
    else
        return ((n%2)+10*decimal_binary(n/2));
}
 
void main()
{
   int no;
 
   printf("Enter a decimal number
");
   scanf("%d",&no);
   printf("Decimal(%d) = Binary(%d)
",no,decimal_binary(no));
}
Source by codedost.com #
 
PREVIOUS NEXT
Tagged: #recursion #convert #decimal #binary
ADD COMMENT
Topic
Name
1+4 =