ive you a number on base ten,you should output it on base two.(0 < n < 1000)
1 2 3
1 1011
题解:十进制转换为二进制
#include<stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> int Bitset(int n) { int i=0,j=0,k; int a[10000];//存储输出 while(n / 2 != 0)//结束标志 { a[i] = n % 2; n = n / 2; i++ ; } if(n != 0)printf("%d",n); while(i--) { printf("%d",a[i]); } printf("\n"); return 0; } int main() { int n; while(scanf("%d",&n) != EOF) { Bitset(n); } return 0; }