#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main()
{
int n;
while(cin>>n)
{
int a[10000]={0};
int i,j,end;
for(i=1,end=0;i<=n;i++)
{
a[0]++;
for(j=0;;j++)
{
if(a[j]==2)
{
a[j+1]++;
a[j]=0;
}
else
{
if(end<j)end=j;//寻找最高位
break;//加不上去的情况就是数值为1的时候
}
}
}
//输出
for(i=end;i>=0;i--)
cout<<a[i];
cout<<endl;
}
}
求n的二进制
最新推荐文章于 2022-10-22 10:54:00 发布