"); //-->
代码
#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=(yc+yb)/2; xr=(xa+xc)/2;yr=(ya+yc)/2; moveto(xp,yp);lineto(xq,yq); lineto(xr,yr);lineto(xp,yp); tria(xa,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); } } int main() { int n,xa=10,ya=10,xb=10,yb=470,xc=630,yc=470; int gdriver=DETECT,gmode; printf("input recursion depth (for example,7):"); scanf("%d",&n); initgraph(&gdriver,&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(); return 0; }
运行
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。