zoukankan      html  css  js  c++  java
  • 一个C语言问题

    在这个题目中,你需要编写一个c++程序,要求输出以下内容:
    0000
    0001
    0010
    .....
    1110
    1111
    (输出0到31的每个数的二进制表示,每行一个,前面的0也必须输出!)

    1)部分代码已经为你完成:

    #include "stdio.h"
    void printall();
    void p(int d);
    void p(char c);
    void pl(int d);
    void p(char *str);
    void pl(char *str);
    
    int main()
    {
    
    printall();
    
    
    return 0;
    }
    
    
    void printall()
    {
    
    	//Your Code Here!
    
    }
    
    void p(int d)
    {
    
    printf("%d",d);
    }
    
    void pl(int d)
    {
    
    printf("%d
    ",d);
    }
    
    
    void p(char c)
    {
    	printf("%c",c);
    }
    
    void pl(char c)
    {
    	printf("%c
    ",c);
    }
    
    void p(char *str)
    {
    	printf("%s",str);
    }
    
    void pl(char *str)
    {
    	printf("%s
    ",str);
    }
    

      

    2)
    只能在printall()方法中添加你的代码。
    *要求:代码所占的字节数尽可能的少。

    这里给一个我写的方法,大家的有更好的么?

    void printall()
    {
    
    #define x(i) c[i]==50?c[i]=48,c[i-1]++:0;
    for (char c[] = "0000", i = 0; i<16; i++, c[3]++){ x(3)x(2)x(1)pl(c); }
    }
    

      

  • 相关阅读:
    工科物理实验()中国大学MOOC答案(已更新)
    类似jar文件使用java无法打开问题
    python9、10章
    nmap的理解与利用(初级)
    常见端口
    配置优化
    删除表操作
    万能的map
    测试
    Mapper.xml
  • 原文地址:https://www.cnblogs.com/xcr1234/p/4550373.html
Copyright © 2011-2022 走看看