HDU
来源:互联网 发布:中性洗涤剂有哪些知乎 编辑:程序博客网 时间:2024/05/22 17:18
Give you a number on base ten,you should output it on base two.(0 < n < 1000)
Input
For each case there is a postive number n on base ten, end of file.
Output
For each case output a number on base two.
Sample Input
1
2
3
Sample Output
1
10
11
#include<stdio.h>
#include<math.h>
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int flag=0,m;
double sum=0;
while(n!=1)
{
m=n%2;
n=n/2;
sum=sum+m*pow(10,flag);
flag++;
}
printf("%.0lf\n",sum+n*pow(10,flag));
}
return 0;
}
十进制转换二进制