http://acm.hdu.edu.cn/showproblem.php?pid=2051
进制转换,十进制转换为二进制输出,模拟方法,
本题是为C语言初学者提供的。 |
【数制换算的一般方法】
|
#include<iostream>
using namespace std;
int main(){
int n,a[50],count;
while(cin >> n)
{
count=0;
while(n)
{
a[count]=n%2;
n/=2;
count ++;
}
for(int i = count-1;i >= 0;i--)
{
cout << a[i];
}
cout << endl;
}
system("pause");
}