个人意见,仅供参考!
1.
//用转意字符
⑴这是输出有前缀“0”的八进制数
int
main(void)
{
int
a;
printf("\n");
scanf("%d",&a);
printf("%#o",a);
/*"%#o"这里的“#”就是输出前缀的,“o”是八进制*/
getch();
return
0;
}
⑵输出无前缀的八进制数
main()
{
int
a;
printf("\n");
scanf("%d",&a);
printf("%o",a);
/*不要在o前加“#”*/
}
——————————————————————————————
2.
//用数据结构的知识解决
int
*Init()
{
int
*top,*base;
base=(int
*)malloc(sizeof(int)
*
50);
if(!base)
{printf("Error!");exit();}
top=base;
return
top;
}
int
*push(int
*top,int
n)
{
*top=n;
top++;
return
top;
}
int
pop(int
*top)
{
int
e;
top--;
e=*top;
return
e;
}
void
convs()
{
int
*top,
*base;
int
e,N;
int
i;
top=Init();
base=top;
printf("Input
the
number:\n");
scanf("%d",&N);
while(N!=0)
{
top=push(top,N%8);
N=N/8;
}
printf("After
change,the
number
is:\n");
while(top!=base)
{
e=pop(top);
top--;
printf("%d",e);
}
printf("\n");
}
main()
{
convs();
getch();
}
格式老是错误,我私信给你了
满意请给采纳,