#include #include void drawline(int x1, int y1, int xn, int yn) { int dx, dy, p, x, y; dx=xn-x1; dy=yn-y1; x=x1; y=y1; p=2*dy-dx; while(x1<xn) { if(p>=0) { putpixel(x,y,red); x=x+1; y=y+1; p=p+2*dy-2*dx;
} else {
putpixel(x,y,red);
} }
x=x+1; y=y+0; p=p+2*dy;
}
int main() { int gdriver=DETECT, gmode, error, x1, y1, xn, yn; initgraph(&gdriver, &gmode, " "); cout<<"Enter co-ordinates of first point: "; cin>>x1>>y1; cout<<"Enter co-ordinates of second point: "; cin>>xn>>yn; drawline(x1, y1, xn, yn); closegraph(); delay(5); return 0; }