Bitset(参考2031题)
题目描述:
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 3Sample Output
1 10 11
通过答案:
#include <stdio.h>
int main(){
int n;
while(scanf("%d",&n)!=EOF){
int y=0,yu,i=1;
while(1){
yu=n%2; //余数
n=n/2; //被除数除以2
y+=yu*i; //i初始为1
i*=10; //i乘以10
if(n<2){
y+=n*i;
break;
}
}
printf("%d\n",y);
}
return 0;
}