十进制保存成2进

  1. #include<stdio.h>  
  2.   
  3. void dectobin(int n);  
  4.   
  5. int main()  
  6. {  
  7.         int x=0;  
  8.         scanf("%d",&x);//只能正数  
  9.     dectobin(x);  
  10.     printf("\n");  
  11.         return 0;  
  12. }  
  13.   
  14. void dectobin(int n)  
  15. {  
  16.     if(n/2>0)  
  17.     {  
  18.         dectobin(n/2);  
  19.         printf("%d",n%2);  
  20.     }  
  21.     else  
  22.     {  
  23.         printf("%d",n);  
  24.     }  
  25. }  

猜你喜欢

转载自blog.csdn.net/qq_40525008/article/details/78987894