Wednesday, July 20, 2011

Program to convert the decimal number into binary using recursive function

/*Serial No.87     [swami61.cpp]*/

#include<stdio.h>
#include<conio.h>
int binary(int n);
void main()
    {
        int z,num;
        printf("Enter number in decimal:=");
        scanf("%d",&num);
        z=binary(num);
        printf("The binary of %d := %d",num,z);
        getch();
    }
int binary(int n)
    {
        int rem,a=1,bin=0;
        if(n==0)
            {
             return(0);
            }
        rem=n%2;
        bin=rem*a+binary(n/2)*a*10;
        return(bin);
    }

No comments:

Post a Comment

If you have any doubt, feel free to ask...