64,649
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
void main()
{
int a;
int count=1,i=31,j = 1;
int b[32] = {0};
int c[32] = {0};
cout <<"Please input a Integer number"<<endl;
cin>>a;
if(a>500000||a <-500000)
{
cout <<"The number is out of bond!";
}
else
{
if(a>=0)
b[0]=0;
else
{
b[0]=1;
a = -a;
}
while(a!=0)
{
b[count] = a %2;
a = a/2;
count++;
}
c[0] = b[0];
j = 1;
for(i = 31;j < count;--i,++j)
{
c[i] = b[j];
}
for(i = 0; i < 32; ++i)
{
cout<<c[i];
}
cout<<endl;
}
}
#include <iostream>;
using namespace std;
void main()
{
int a;
int count=1,i=1;
int b[20],c[20];
cout <<"Please input a Integer number";
cin>>a;
if(a>500000||a <-500000){
cout <<"The number is out of bond!";
}
else{ if(a>=0)b[0]=0;
else b[0]=1;
while(a!=0){
b[count] = a %2;
a = a/2;
count++;
}
count--;
c[0] = b[0];
for(count;count>=1;count--){
c[i] = b[count];
i++;
}
for(int j=0;j<i;j++)
cout <<c[j];
}
}