#include iostream
#include<Windows.h>
using namespace std;
int main(void){
int x;
int i;
int number[32]={0};
cout<<“请输入整数”;
cin>>x;
while(x<0){
cout<<“请输入正整数”;
system(“pause”);
return 1;
}
i=0;
while(x!=0){
number[i]=x % 2; //取余,
x=x / 2;
i++;
}
for(i–;i>=0;i–){
cout<<number[i];
}
system(“pause”);
return 0;
}
运算时一定要记住空格隔开加减乘除,
正整数二进制转换代码
最新推荐文章于 2023-11-30 01:20:00 发布