趁着复习把课上的作业和代码上传上来嘿嘿嘿,这个系列的代码都是自己写的或者老师教学用的可能内存管理上有点小瑕疵,但是算法理解还是不错的!本系列所有代码在dev-cpp上可以跑通~
描述:
给你一个十进制的数字,转换成八进制。
思路:
和C语言的东西一样把,疯狂取模,然后\就可以做到了,当时的问题是他会反过来,但现在有栈FILO的性质就刚好对应上了。
代码:
#include<stdio.h>
int main(){
int n;
int stack[100];
int top=0;
scanf("%d",&n);
int t=n;
if(t==0){
stack[top++]=0;
}
while(t!=0){
stack[top++]=t%8;
//printf("%d\n",stack[top-1]);
t/=8;
}
while(top){
printf("%d",stack[--top]);
}
return 0;
}