hdu 2051.bitset 题解 代码

Problem ## Description
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

题解

水题,简单的十进制转二进制

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<stdio.h>
#include<string.h>
#define maxn 11
int num[maxn];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int cou=0;
for(int i=0;n!=0;i++)
{
num[i]=n%2;
n/=2;
cou++;
}
for(int t=0;t<cou;t++)
{
printf("%d",num[cou-t-1]);
}
printf("n");
}
return 0;
}