Skip to content

Instantly share code, notes, and snippets.

@ahmedeshaan
Created January 16, 2015 18:31
Show Gist options
  • Save ahmedeshaan/920b4a12acd573cace1e to your computer and use it in GitHub Desktop.
Save ahmedeshaan/920b4a12acd573cace1e to your computer and use it in GitHub Desktop.
// Solution for: Take an integer(DECIMAL) input and convert it to Octal
int main()
{
int octal_output[10];
int i=1,j,n=-264;
// To avoid Negative Input
if(n<0) {
n = n +(-n*2);
}
while(n) {
// Put Moulous input in an array
binary_output[i] = n % 8;
// Devided nth number by 2 in round
n /= 8;
i++;
}
for(j=i-1; j>=1;j--) {
// Print the stored array input
printf("%d",octal_output[j]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment