#include
#include
#include
#include
#include
void main()
{
int i, gd, gm;
float x, y, x1, y1, x2, y2, x_incr, y_incr, length, dx, dy, m;
printf("enter the value of x1:");
scanf("%f", &x1);
printf("\n enter the value of y1:");
scanf("%f", &y1);
printf("\n enter the value of x2:");
scanf("%f", &x2);
printf("\n enter the value of y2:");
scanf("%f", &y2);
detectgraph(&gd, &gm);
initgraph(&gd, &gm, " ");
setbkcolor(7);
dx = abs(x2 - x1);
dy = abs(y2 - y1);
m = dy / dx;
printf("Slope=%f", m);
if (dx >= dy)
{
length = dx;
}
else
{
length = dy;
}
x_incr = abs(x2 - x1) / length;
y_incr = abs(y2 - y1) / length;
x = x1;
y = y1;
putpixel(x, y, 12);
i = 1;
while (i <= length)
{
x = x + x_incr;
y = y + y_incr;
putpixel(x, y, 12);
printf("\n %f %f", x, y);
i = i + 1;
delay(50);
}
getch();
closegraph();
}