UncleCoder.com

UncleCoder.com

Free programming examples and instructions

C program to convert decimal to binary using recursion

C program for how to convert decimal to binary using recursion

by Krishna viswambharan


Posted on 31 Oct 2017 Category: C Views: 491

Edited on 30 May 2018


C program to convert decimal to binary using recursion

Recursion is a process by which a function calls itself repeatedly until some specified condition has been satisfied.  The process is used for repetitive computations in which each action is stated in terms of a previous result. Many iterative problems can be written in this form.

Below C program is an example of recursion and the Source code is given as follows. The program compiled successfully and the output is also shown below.

#include <stdio.h>
#include <conio.h>
void tobin(int);
void main()
{
        int num;
        printf(“Enter the decimal number :”);
        scanf(“%d”,&num);
        printf(“Binary =”);
        tobin(num);
        getch();
}
void tobin(int n)
{
       if(n>1)
       tobin(n/2);
       printf(“%d”,n%2);
}

output



Leave a Comment:


Advertisement