码迷,mamicode.com
首页 > 其他好文 > 详细

将十进制转换成二进制输出,递归写法

时间:2014-10-09 01:27:27      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   sp   div   c   log   

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void binary_num(int, int);
int main( int argc, char* argv[] ) 
{
    
    int a = 30;
    binary_num(a, sizeof(a) * 8);

    printf("\n");
    system("pause");
    return 0;
}

void binary_num(int a, int i)
{
    if (i > 1)    
        binary_num(a >> 1, --i );    
    if (a & 1)
        printf("1");
    else
        printf("0");
}    

 

将十进制转换成二进制输出,递归写法

标签:style   blog   color   io   ar   sp   div   c   log   

原文地址:http://www.cnblogs.com/yyxayz/p/4011562.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!