用栈实现进制转换

#include<iostream>
#include<stack>
using namespace std;
void Conversion (int N)
{
	int x;
	stack<int> s;
	if(N==0)
	{
		printf("%d\n",0);
		return ;
	}
	while(N>0)
	{
		x=N%2;
		s.push(x);
		N=N/2;
	}
	while(!s.empty())
	{
		x=s.top();
		printf("%d",x);
		s.pop();
	}
	printf("\n");
}
int main()
{
	int N;
	while(scanf("%d",&N)!=EOF)
		Conversion(N);
	return 0;
}

  

 

posted @ 2012-08-02 14:17  myth_HG  阅读(413)  评论(0编辑  收藏  举报