|
- #include <stdio.h>
- void to_binary(unsigned long);
- char buf[32];
- int main()
- {
- unsigned long pn;
- int i;
- scanf("%lu", &pn);
- to_binary(pn);
- for(i=0; i!=3; ++i)
- printf("%d", buf[i]);
- putchar(' ');
- for(; i != 9; ++i)
- printf("%d", buf[i]);
- putchar(' ');
- for(; i != 11; ++i)
- printf("%d", buf[i]);
- putchar('\n');
- return 0;
- }
- void to_binary(unsigned long x)
- {
- int pos = 10;
- for(pos = 10; pos >= 0; --pos){
- buf[pos] = x % 2;
- x /= 2;
- }
- }
复制代码 |
|