Skip to content

Instantly share code, notes, and snippets.

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