#include <stdio.h>
int main()
{
int n;
printf ("n = ");
scanf ("%d", &n);
int b[100] = {0};
int i = 0;
while (n)
{
b[i++] = n % 8;
n = n / 8;
}
int j;
for (j = i; j >= 0; j--)
{
printf ("%d", b[j]);
}
printf ("\n");
return 0;
int main()
{
int n;
printf ("n = ");
scanf ("%d", &n);
int b[100] = {0};
int i = 0;
while (n)
{
b[i++] = n % 8;
n = n / 8;
}
int j;
for (j = i; j >= 0; j--)
{
printf ("%d", b[j]);
}
printf ("\n");
return 0;
}
这里用到了一个思想就是逆向输出。