Decimal to binary (not through array)

#include<iostream>
using namespace std;
int main()
{
int n,result,k,i,temp;;
while(cin>>n)
{
result=0,k=1;
temp = n;
while(temp)
{
i = temp%2;
result = k * i + result;
k = k*10;
temp = temp/2;
}
cout<<result<<endl;
}
return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325518031&siteId=291194637