这是一个函数曲线的描绘问题,可根据注释修改程序,以画出不同的曲线。 #include<graphics.h>#define y(x) x*x /*在这里修改曲线方程,此处为x的平方*/#define xs(x) x0+x*s /*这里为x方向的坐标转换*/#define ys(x) y0-y(x)*s /*这里为y方向的坐标转换*/ main(){float x0,y0,xl,xr,s,x,dx; int driver=DETECT,mode; printf("Please input the x and y of new location:"); scanf("%f %f",&x0,&y0); /*输入要画曲线的坐标系原点坐标*/ printf("Please input the multiply:"); scanf("%f",&s); /*曲线放大倍数,以几十为效果最佳*/ printf("Please input the left edge and the right edge and dx:"); scanf("%f %f %f",&xl,&xr,&dx); /*输入曲线的自变量上下界xl和xr以及自变量的递增步长*/ registerbgidriver(EGAVGA_driver); initgraph(&driver,&mode,""); line(x0,getmaxy(),x0,0); line(0,y0,getmaxx(),y0); outtextxy(x0,y0,"0,0"); setcolor(14); while(ys(xl)<0)xl+=dx; moveto(xs(xl),ys(xl)); for(x=xl;x<=xr;x+=dx) {if(x>xl&&ys(x)>=0) {putpixel(xs(x),ys(x),14); lineto(xs(x),ys(x)); } } getch(); closegraph();}

评论