#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,d,inc_r,inc_ru,x,y; 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 */ dx=p2.x-p1.x; dy=p2.y-p1.y; d=2*dy-dx; inc_r=2*dy; inc_ru=2*(dy-dx); x=p1.x; y=p1.y; putpixel(x,y,1); if (dx > dy) { d=2*dy-dx; inc_r=2*dy; inc_ru=2*(dy-dx); while (x < p2.x) { if (d <= 0) { d+=inc_r; x++; } else { x++; y++; d+=inc_ru; } putpixel(x,y,1); } } else { d=2*dx-dy; inc_r=2*dx; inc_ru=2*(dx-dy); while (y < p2.y) { if (d <= 0) { d+=inc_r; y++; } else { x++; y++; d+=inc_ru; } putpixel(x,y,1); } } getche(); closegraph(); /* Return the system to text mode */ }