实验二 十进制转化为二进制
程序员文章站
2022-07-15 10:14:05
...
#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;
}