正文

C画函数曲线2007-12-14 22:35:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/tld5yj/31427.html

分享到:

这是一个函数曲线的描绘问题,可根据注释修改程序,以画出不同的曲线。 #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();}

阅读(7531) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册