#include <iostream>
using namespace std;
#define M 10
int main ()
{
int n;
cout<<"请输入一个10进制数:"<<endl;
cin>>n;
int h=0,b,k=1;
while(n!=0)
{
b=n%2;
k=k*10;
n=n/2;
h=k*b+h;
}
cout<<"这个数的2进制为:"<<h<<endl;
return 0;
}
#include <iostream>
using namespace std;
#define M 10
int main ()
{
int n;
cout<<"请输入一个10进制数:"<<endl;
cin>>n;
int h=0,b,k=1;
while(n!=0)
{
b=n%2;
k=k*10;
n=n/2;
h=k*b+h;
}
cout<<"这个数的2进制为:"<<h<<endl;
return 0;
}