Decimal Binary recursive transfer: enter a positive integer n, which is converted to the binary outputs

Man of few words said, look at the following code to achieve

#include <stdio.h>
#include <string.h>
void dectobin(int n)
{
 if (n == 0)
  return;
 else
 {
  dectobin(n / 2);
  printf("%d", n % 2);
 }
 
}
int main()
{
 int n;
 scanf_s("%d", &n);
 dectobin(n);
 return 0;
}

Oh, welcome to discuss

Guess you like

Origin www.cnblogs.com/gaoyutao/p/11962172.html