#include<graphics.h>
#include<stdio.h>
void dda_line(float x1,float y1,float x2,float y2)
{
float x,y,x3,y3,n,t;
int color=2;
x3=x2-x1;y3=y2-y1;
n=fabs(x3);t=fabs(y3);
if(t>n)n=t;
if(n!=0.0)
{
x=x3/n;y=y3/n;
}
x1=x1+0.5;y1=y1+0.5;
x3=(int)x1;y3=(int)y1;
x2=(int)(x2+0.5);y2=(int)(y2+0.5);
n=fabs(x3-x2);t=fabs(y3-y2);
if(t>n)n=t;putpixel(x3,y3,8);
while(n>0)
{
x1=x1+x;y1=y1+y;n=n-1;putpixel(x1,y1,color);
}
}
void main()
{ float x1,x2,y1,y2;
int graphdriver=DETECT,graphmode;
initgraph(&graphdriver,&graphmode,"");/*.........................*/
printf("x1:\n");
scanf("%f",&x1);
printf("y1:\n");
scanf("%f",&y1);
printf("x2:\n");
scanf("%f",&x2);
printf("y2:\n");
scanf("%f",&y2);
dda_line(x1,y1,x2,y2);
getch();
}