忘了从哪个哥们看到的思想。。。。。话说我更喜欢itoa()函数的说,可是n诺不让用,说是编译错误。。。。。
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main()
{
int n;
int a[55];
while(cin>>dec>>n)
{
int i=0;
while(n)
{
a[i++] = n%2;
n=n/2;
}
for(int j=i-1;j>=0;j--)
cout<<a[j];
cout<<endl;
}
return 0;
}
用itoa()函数的。。。。
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main()
{
int n;
char s[50];
while(cin>>dec>>n)
{
itoa(n,s,2);
cout<<s<<endl;
}
return 0;
}