#include #include #include #include void main() { int GraphDriver; /* The Graphics device driver */ int GraphMode; /* The Graphics mode value */ struct point { int x,y; } p1,p2; int dx,dy,e,inc_x,inc_y,x,y,c1,c2,i; printf("give me the first point--->"); scanf("%d %d",&p1.x,&p1.y); printf("give me the second point--->"); scanf("%d %d",&p2.x,&p2.y); printf("(%d,%d) to (%d,%d)\n",p1.x,p1.y,p2.x,p2.y); getche(); GraphDriver = DETECT; /* Request auto-detection */ initgraph( &GraphDriver, &GraphMode, "" ); /* just increasing p1 - p2 */ line(p1.x,p1.y,p2.x,p2.y); getche(); dx=abs(p2.x-p1.x); dy=abs(p2.y-p1.y); if (p2.x >= p1.x) inc_x=1; else inc_x=-1; if (p2.y >= p1.y) inc_y=1; else inc_y=-1; x=p1.x; y=p1.y; putpixel(x,y,1); if (dx > dy) { e=2*dy-dx; c1=2*(dy-dx); /* select upper one */ c2=2*dy; for (i=0; i= 0) { y+=inc_y; e+=c1; } else e+=c2; x+=inc_x; putpixel(x,y,14); } } else { e=2*dx-dy; c1=2*(dx-dy); /* select upper one */ c2=2*dx; for (i=0; i= 0) { x+=inc_x; e+=c1; } else e+=c2; y+=inc_y; putpixel(x,y,14); } } getche(); closegraph(); /* Return the system to text mode */ }