中点画线法,
#include <graphics.h>#include <stdio.h>
#include <conio.h>
main()
{
int gd,gm;
int x1,y1,x2,y2,x,y;
float a,b,c,d,d1,d2;
gd=DETECT;
initgraph(&gd,&gm,"D:\\CG\\TC20H\\$_OUTDIR\BGI");
printf("please input two point(x1,y1,x2,y2,x1<x2):");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
a=y1-y2;
b=x2-x1;
putpixel(x1,y1,2);
getch();
x=x1,y=y1;
d=2*a+b;
d1=2*a;
d2=2*(a+b);
while(x<=x2)
{
if (d>=0) {++x;d=d+d1;}
else {x++;y++;d=d+d2;}
putpixel(x,y,2); getch();
}
closegraph();
}
我用的是TC,帮找下错误写谢了