Friday, March 7, 2014

WRITE A FUNCTION TO CALCULATE THE BINARY EQUIVALENT OF A NUMBER WITH DECIMAL BASE USING RECURSION

#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
int binary(int*,int,int);
int num,a[10],i=0;
clrscr();
printf("enter the number\n");
scanf("%d",&num);
i=binary(a,num,i);
i--;
printf("the binary equivalennt of %d is ",num);
for(;i>=0;i--)
printf("%d",a[i]);
getch();
}

int binary(int*p,int n,int i)
{
if(n>=1)
{
*(p+i)=n%2;
i++;
binary(p,n/2,i);
}
else
return(i);
}

No comments:

Post a Comment