一个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\n",d);
}


void p(char c)
{
	printf("%c",c);
}

void pl(char c)
{
	printf("%c\n",c);
}

void p(char *str)
{
	printf("%s",str);
}

void pl(char *str)
{
	printf("%s\n",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); }
}

  

 

posted @ 2015-06-03 21:55  &amp;nbsp;  阅读(306)  评论(0)    收藏  举报