#16695: 拜託!!各位大大說明一下哪裡錯了(該如何改


kolagh7486 (電腦前的咖啡)


#include<iostream>

using namespace std;

int x;
void carry(int);


int main()
{
while(cin>>x)
carry(x);


}

void carry(int x)
{
if(x>=2)
{
carry(x/2);
cout<<x%2;
}
if(x<2)
{
cout<<x;
}

}

 

#16697: Re:拜託!!各位大大說明一下哪裡錯了(該如何改


shkevin (kevin)


#include

using namespace std;

int x;
void carry(int);


int main()
{
while(cin>>x)
carry(x);


}

void carry(int x)
{
if(x>=2)
{
carry(x/2);
cout<<x%2;
}
if(x<2)
{
cout<<x;
}

}

 

 

 


每次輸出答案後要換行, 所以你缺少了換行
補上換行符號就行了

int main()
{
while(cin>>x)
{ carry(x); cout <<endl; } }