#include <graphics.h>
#include <stdio.h>
void tria(xa,ya,xb,yb,xc,yc,n)
int xa,ya,xb,yb,xc,yc,n;
{
int xp,yp,xq,yq,xr,yr;
if (n>0)
{
xp=(xa+xb)/2; yp=(ya+yb)/2;
xq=(xb+xc)/2; yq=(yb+yc)/2;
xr=(xc+xa)/2; yr=(yc+ya)/2;
moveto(xp,yp); lineto(xq,yq);
lineto(xr,yr); lineto(xp,yp);
tria(xq,ya,xp,yp,xr,yr,n-1);
tria(xb,yb,xq,yq,xp,yp,n-1);
tria(xc,yc,xr,yr,xq,yq,n-1);
}
}
main()
{
int n=7,xa=10,ya=10,xb=10,yb=470,xc=630,yc=470;
int gdrive=DETECT,gmode;
initgraph(&gdrive,&gmode,"C:\\tc");
cleardevice();
setbkcolor(9); setcolor(4);
moveto(xa,ya); lineto(xb,yb);
lineto(xc,yc); lineto(xa,ya);
tria(xa,ya,xb,yb,xc,yc,n);
getch();
closegraph();
}