/* program to draw a line using DDA algorithm. */

Description :
In Digital differential analyzer (DDA) algorithm we first need both the end point of line.
And we can take any one point and start moving towards another point.

Program :

copy
```
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gdriver = DETECT, gmode;
int i, x1, y1, x2, y2;
float dx, dy, step;
float x, y, xinc, yinc;
initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
printf("Enter the x - cordinate value of first point : ");
scanf("%d",&x1);
printf("Enter the y - cordinate value of first point : ");
scanf("%d",&y1);
printf("Enter the x - cordinate value of second point : ");
scanf("%d",&x2);
printf("Enter the y - cordinate value of second point : ");
scanf("%d",&y2);
dx = abs(x2 - x1);
dy = abs(y2 - y1);
if( dx > dy )
step = dx;
else
step = dy;
xinc = dx / step;
yinc = dy / step;
x = x1;
y = y1;
for(i=0;i<step;i++)
{
x = x + xinc;
y = y + yinc;
putpixel(x,y,5);
}
getch();
closegraph();
}
```

Output :
Executed and tested in Turbo C 3.2
Written with ♥ from
Mangesh .