#include<stdio.h>
#include<graphics.h>
void MidpointLine(x0,y0,x1,y1,color)
int x0,x1,y0,y1,color;
{int x,y,mid,dx,dy,d_up,d_down;
dy=y1-y0;dx=x1-x0;
mid=dx-2*dy;
d_up=2*dx-2*dy;d_down=-2*dy;
x=x0;y=y0;
while(x<=x1)
{putpixel(x,y,color);
x++;
if(mid<0){y++;mid=mid+d_up;}
else mid=mid+d_down;
}
}
main()
{int gb=DETECT,gm;
initgraph(&gb,&gm," ");
MidpointLine(100,100,300,200,14);
getch();
closegraph();
}