728x90
#include <stdio.h>
#define MAX_LEVEL 7
#define MAX_WIDTH 50
char screen[MAX_LEVEL][MAX_WIDTH];
void init()
{
int i,j;
for(i=0;i<MAX_LEVEL;i++)
for(j=0;j<MAX_WIDTH;j++)
screen[i][j]='-';
}
void draw_tree(int row, int left, int right)
{
int mid,k,i=1,a,b,c=1;
for(k=1;k<7;k++)
{
i*=2;
b=1;
if((right-left)<3)
{
return;
}
if(k==1)
{
mid=(left+right)/2;
screen[row][mid]='x';
}
else
{
c=i-1;
for(a=i;a>0;a-=2)
{
mid=((a*left)+(b*right))/i;
screen[row+k-1][mid]='x';
b+=2;
}
}
}
}
void display()
{
int a,b;
for(a=0;a<MAX_LEVEL;a++)
{
for(b=0;b<MAX_WIDTH;b++)
{
printf("%c",screen[a][b]);
}
printf("\n");
}
}
main()
{
init();
draw_tree(0,0,MAX_WIDTH-1);
display();
}
728x90