实验二 十进制转化为二进制

#include<iostream>
using namespace std;
const int Stacksize=10;
class SeqStack
{
public:
	SeqStack(){top=-1;}
	~SeqStack(){}
	int top;
	int data[Stacksize];
};


int main()
{
	int x;
	SeqStack s;
	s.top=-1;
	cout<<"请输入十进制的数:"<<endl;
	cin>>x;
	cout<<x;
	do
	{
		s.top++;
		s.data[s.top]=x%2;
		x=x/2;
	}while(x!=0);
	cout<<"的二进制为:";
	do
	{
		cout<<s.data[s.top];
		s.top--;
	}while(s.top!=-1);
	cout<<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/nika_jy_L/article/details/80261513