余数入栈,整数自除
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
int stack[10000]={0};
int top=-1;
int num;
scanf("%d",&num);
while(num){
stack[++top]=num%2;//余数入栈
num/=2;//整数自除
}
while(top!=-1){
printf("%d",stack[top--]);
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发