

无一分可增不叫完美,无一分可减才是。--Antoine de Saint-Exupery



进制转换
编程,输入一个10进制正整数,然后输出它所对应的八进制数。
输入格式
无
输出格式
无
输入样例
10
输出样例
12
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5int main()
6{
7 int num;
8 scanf("%d", &num);
9
10 printf("%o", num);
11
12 return 0;
13}
1#include <stdio.h>
2
3int main()
4{
5 int num;
6 scanf("%d", &num);
7
8 int rest = num % 8; //rest用来保留最后一位
9 while (num / 8 != 0)
10 {
11 num = num / 8;
12 putchar(num + '0'); //以ascii码的形式打印
13 }
14 putchar(rest + '0');
15
16 return 0;
17}


“If you torture the data enough, it will confess”
- - Ronald Coase




本文分享自微信公众号 - 电子荣耀(gh_05453579ed9d)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。