Skip to content

Instantly share code, notes, and snippets.

@ahmedeshaan
Last active August 29, 2015 14:15
Show Gist options
  • Save ahmedeshaan/2d5414fbdd6424f3f1d6 to your computer and use it in GitHub Desktop.
Save ahmedeshaan/2d5414fbdd6424f3f1d6 to your computer and use it in GitHub Desktop.
//Decimal To Binary Recursive function
#include <stdio.h>
#include <stdlib.h>
int arg;
int newVar;
int modulus[10];
int i=0;
void myFunction(arg){
if(arg<=0){
return 1;
}else {
modulus[i] = arg % 2;
//printf("%d \n",modulus[i]);
arg = arg / 2;
i++;
}
myFunction(arg);
}
void yourFunction(arg){
printf("%d",modulus[arg]);
if(arg <= 0){
return 1;
}
yourFunction(arg - 1);
}
int main()
{ int n=0;
printf("Insert you Decimal Number: ");
scanf("%d",&n);
if(n<0){
n = -1*(n);
}
myFunction(n);
yourFunction(i-1);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment