This is a simple piece of code that i wrote to convert decimals to binary.

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

int

quotient (int n)

{

int y = floor(n/2);

return y;

}

int

main(int argc, char **argv)

{

int n = atoi(argv[1]);

while(n>0){

printf("%d", n%2);

n = quotient(n);

}

printf("\n");

return 0;

}

Now, obviously i need to reverse the output in order to get the binary equivalent. Can someone please tell me the easiest way of doing this?

Is it possible for me to put the output in an array and then reverse it?

int

main(int argc, char **argv)

{

int n = atoi(argv[1]);

while(n>0){

c[12]=n%2;

printf("%d", c[12]);

n = quotient(n);

}

printf("\n");

printf("%d", c[12]);

return 0;

}

But c[12] doesn't seem to remember the numbers. Any help appreciated. thanks.