十进制数到二进制数的转换.c 343 B

12345678910111213141516171819202122232425
  1. #include <stdio.h>
  2. void exchange(int x, int b[], int *size) {
  3. int i = 0;
  4. while (x > 0) {
  5. b[i++] = x % 2;
  6. x /= 2;
  7. }
  8. *size = i;
  9. }
  10. int main() {
  11. int x, size, b[50], i;
  12. scanf("%d", &x);
  13. exchange(x, b, &size);
  14. for (i = size - 1; i >= 0; i--) {
  15. printf("%d", b[i]);
  16. }
  17. return 0;
  18. }