#include
using namespace std;
int main()
{
int number;
int yushu;
int shuzu[20];
int i = 0;
cout << "Please enter an integer[n](1<=n<=200000): " << endl;
cin >> number;
while (number > 0)
{
yushu = number % 2;
if (yushu == 0)
{
shuzu[i] = 0;
}
else
{
shuzu[i] = 1;
}
number = (number - yushu) / 2;
i++;
}
for (i; i >= 0; i--)
{
cout << shuzu[i];
}
system("Pause");
return 0;
}
少了一句
#include<iostream>
using namespace std;
int main()
{
int number;
int yushu;
int shuzu[20];
int i = 0;
cout << "Please enter an integer[n](1<=n<=200000): " << endl;
cin >> number;
while (number > 0)
{
yushu = number % 2;
if (yushu == 0)
{
shuzu[i] = 0;
}
else
{
shuzu[i] = 1;
}
number = (number - yushu) / 2;
i++;
}
i = i - 1; //循环结束的时候i指在数组有效值的后一位
for (; i >= 0; i--)
{
cout << shuzu[i];
}
system("Pause");
return 0;
}