八进制
题目截图:
思路:
简单模拟。详情请看另一篇博客。
代码如下:
1 /* 2 八进制 3 */ 4 5 #include <stdio.h> 6 #include <string.h> 7 #include <math.h> 8 #include <stdlib.h> 9 #include <time.h> 10 11 int o[10]; // 存储八进制的每一位 12 13 int main() { 14 int N; 15 while(scanf("%d", &N) != EOF) { 16 int i, len=0; 17 while(N != 0) { // 逆序求八进制,并存储 18 o[len++] = N%8; 19 N /= 8; 20 } 21 // 倒序输出,即所求的八进制 22 for(i=len-1; i>=0; --i) { 23 printf("%d", o[i]); 24 } 25 printf("\n"); 26 } 27 28 return 0; 29 }