Give you a number on base ten,you should output it on base two.(0 < n < 1000)
InputFor each case there is a postive number n on base ten, end of file.OutputFor each case output a number on base two.Sample Input
1
2
3
Sample Output
1
10
11
#include<stdio.h>
int main()
{
int n,k,t;
while(scanf("%d",&n)!=EOF)
{
k=0;
t=1;
while(n!=0)
{
k+=(n%2)*t;
n=n/2;
t*=10;
}
printf("%d\n",k);
}
return 0;
}
题解:循环就好。
未知多少组测试数据,用while(scanf("%d",&n)!=EOF)。