Pages

Write a c language program to convert decimal to binary using recursion.

Monday, 15 July 2013

#include <stdio.h>
#include <conio.h>
long DecToBin(int); //declaration

int main(){

    long BinNo;
    int DecNo;

    printf("Enter any decimal number: ");
    scanf("%d",&DecNo);

    BinNo = DecToBin(DecNo);
    printf("Binary value is: %ld", BinNo);

    getch();
}
//definition
long DecToBin(int DecNo)
{

    static long BinNo,remainder,factor = 1;

    if(DecNo != 0)
    {

         remainder = DecNo % 2;
         BinNo = BinNo + remainder * factor;
         factor = factor * 10;
         DecToBin(DecNo / 2);
    }

    return BinNo;
}

 

Search Box

Most Reading

Contact Form

Name

Email *

Message *