#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#define ROUND(a) ((int) (a+0.5))
void line DDA(int xa,int ya,int xb,int yb)
{
int dx,dy,steps,k,R;
float xincrement,yincrement,x,y;
dx=xb-xa;
dy=yb-ya;
if(abs(dx)>abs(dy))
steps=abs(dx);
else
steps=abs(dy);
xincrement=dx/steps;
yincrement=dy/steps;
x=xa;
y=ya;
putpixel(ROUND(x),ROUND(y),1);
for(k=0;k<steps;k++)
{
x=x+xincrement;
y=y+yincrement;
putpixel(ROUND(x),ROUND(y),1);
}
}
int main()
{
int x1,x2,y1,y2,round;
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, "");
printf("Enter value of x1");
scanf("%d",&x1);
printf("Enter value of x2");
scanf("%d",&x2);
printf("Enter value of y1");
scanf("%d",&y1);
printf("Enter value of y2");
scanf("%d",&y2);
lineDDA(x1,x2,y1,y2);
close graph();
return 0;
}